⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dot11timerlib.c

📁 PNE 3.3 wlan source code, running at more than vxworks6.x version
💻 C
📖 第 1 页 / 共 2 页
字号:
    dot11TimerLib.pHead = NULL;    dot11TimerLib.lastTimerId = 0;    /* Kill the message queue after the task */    if (msgQDelete(dot11TimerLib.timerQueue) != OK)        {        DOT11_TIMER_LOG("dot11TimerDestroy: Error deleting msgq\n",                        0,0,0,0,0,0);            return ERROR;        }    /* There is no memPartDestroy() routine, so we need to manually    delete the descriptor */    free(dot11TimerLib.memPart->id);    DOT11_TIMER_LOG("dot11TimerDestroy: Gone!\n",0,0,0,0,0,0);    return OK;        }/***************************************************************************** dot11TimerShow - Show routine for the time library** This routine shows basic information on the timer library and a list of all* timers currently running.** RETURNS: none** ERRNO: N/A*/STATUS dot11TimerShow()    {    DOT11_TIMER * pBug;    if (dot11TimerUsage == 0)        {        printf("Timer library not initialized\n");        return ERROR;        }    printf("Last timer ID = %d\n", dot11TimerLib.lastTimerId);        if (dot11TimerLib.pHead == NULL)        {        printf("No timers set \n");        }    else        {        for (pBug = dot11TimerLib.pHead; pBug != NULL; pBug = pBug->pNext)            {            printf("   TIMER %d >> ft = %d delay=%ld\n", pBug->timerId,                    pBug->fireTime, pBug->fireTime - tickGet());            }        }    /* Display timer statistics */    printf("Timer allocations errors    %d\n",            dot11TimerLib.memPart->allocError);    printf("Timer deallocations errors  %d\n",            dot11TimerLib.memPart->freeError);    printf("Timer allocations success   %d\n",            dot11TimerLib.memPart->allocSuccess);    printf("Timer deallocations success %d\n",            dot11TimerLib.memPart->freeSuccess);    return OK;    }/***************************************************************************** dot11TimerTask - Central task for the timer library** This task runs continuously.  It pends on msgQReceive(), but uses the timeout* feature of msgQReceive() to ensure that it will wake up before the next* event, even if there hasn't been any messages.** RETURNS: none** ERRNO: N/A*/LOCAL void dot11TimerTask()    {    INT32 nextEvent = WAIT_FOREVER;  /* Next wakeup point */    DOT11_TIMER_REQ req;             /* Buffer to read request into */    STATUS status;    DOT11_TIMER * pBug;    FOREVER        {                status = msgQReceive(dot11TimerLib.timerQueue, (char *)&req,                     sizeof(DOT11_TIMER_REQ), nextEvent);        DOT11_TIMER_LOG("dot11TimerTask: running\n",0,0,0,0,0,0);        /* Perform the operation we just dequeued, if a message was dequeued.          A status of ERROR could mean several things, including a simple         timeout */        if ((status != ERROR) &&(dot11TimerOpFuncs[req.operation] != NULL))            {            (dot11TimerOpFuncs[req.operation])(&req);            }        if (req.operation == DOT11_TIMER_QUIT)            {            /* Flush all timers from the queue */            dot11TimerFlush();            break;            }        /* See if any events timed out */        while ((dot11TimerLib.pHead != NULL) &&                (dot11TimerLib.pHead->fireTime <= tickGet()))            {            DOT11_TIMER_LOG("dot11TimerTask: event running tid=%d\n",                            dot11TimerLib.pHead->timerId,0,0,0,0,0);                        /* Call the action from tNetTask()*/            if (netJobAdd(dot11TimerLib.pHead->action,                          dot11TimerLib.pHead->actionParam0,                           dot11TimerLib.pHead->actionParam1,2,3,4) != OK)                {                DOT11_TIMER_LOG("Error adding timer netJob\n",0,0,0,0,0,0);                /* Just call it directly, so that the event is not lost. */                (dot11TimerLib.pHead->action)(dot11TimerLib.pHead->actionParam0,                                              dot11TimerLib.pHead->actionParam1);                }            /* Remove the timer */            pBug = dot11TimerLib.pHead;            dot11TimerLib.pHead = dot11TimerLib.pHead->pNext;            DOT11_TIMER_FREE((char*)pBug);            }        /* Calculate the next delay time*/        if (dot11TimerLib.pHead == NULL)            {            nextEvent = WAIT_FOREVER;            }        else            {            /* Calculate how long we need to wait for the next message */            nextEvent = (dot11TimerLib.pHead->fireTime - tickGet());            if (nextEvent < 0)                {                nextEvent = NO_WAIT;                }            }                req.operation = DOT11_TIMER_NOP;        }    DOT11_TIMER_LOG("dot11TimerTask: deleting\n",0,0,0,0,0,0);    /* Permanent existential discontinuity */    }/***************************************************************************** dot11TimerOpAdd - Adds a timer to the timer list** This routine inserts a timer on the timer list.  Since the timer list is * sorted by firing time, the entry is added in the appropriate place.  In the* event of multiple events firing at the same time, the new event is placed* after all the existing events to fire at that time** RETURNS: OK or ERROR on allocation error** ERRNO: N/A*/LOCAL STATUS dot11TimerOpAdd    (    DOT11_TIMER_REQ * pReq    )    {    DOT11_TIMER *   pNewTimer;    DOT11_TIMER *   pBug;    if (dot11TimerUsage == 0)        {        DOT11_TIMER_LOG("dot11TimerOpAdd: not initialized\n",0,0,0,0,0,0);        return ERROR;        }        /* Sanity check */    if (pReq->operation != DOT11_TIMER_ADD)        {        DOT11_TIMER_LOG("dot11TimerOpAdd: Not addition msg\n",0,0,0,0,0,0);        return ERROR;        }    if ((pNewTimer =          (DOT11_TIMER *)DOT11_TIMER_ALLOC(1, sizeof(DOT11_TIMER)))         == NULL)        {        DOT11_TIMER_LOG("dot11TimerOpAdd: allocation error\n",0,0,0,0,0,0);        return ERROR;        }        pNewTimer->timerId = pReq->timerId;    pNewTimer->fireTime = pReq->fireTime;    pNewTimer->action = pReq->actionPtr;    pNewTimer->actionParam0 = pReq->param0;    pNewTimer->actionParam1 = pReq->param1;        /* Link the new timer into the LL - a sorted insertion */    if ((dot11TimerLib.pHead == NULL) ||         (dot11TimerLib.pHead->fireTime > pNewTimer->fireTime))        {        /* This is the easiest case.  If there's nothing on the queue or         nothing to fire earlier on the queue, then this just becomes the         first item on the queue */        pNewTimer->pNext = dot11TimerLib.pHead;        dot11TimerLib.pHead = pNewTimer;        }    else        {        /* We know that the first item on the queue is earlier or the same         firetime as us.  Thus, search for either the packet before the end of        the queue or the last packet before the first one with a greater         firetime than us */        pBug = dot11TimerLib.pHead;                while ((pBug->pNext != NULL) && (pBug->pNext->fireTime <=                                          pNewTimer->fireTime))            {            pBug = pBug->pNext;            }                /* Now we know that we need to insert after pBug */        pNewTimer->pNext = pBug->pNext;        pBug->pNext = pNewTimer;        }    return OK;    }/***************************************************************************** dot11TimerOpDel - Deletes a specific entry on the timer list** This function searches all of the entries on the timer queue.  If one matches* the given <timerId>, then it will be deleted.** The case where the timer has already been deleted is accounted for.** RETURNS: OK or ERROR if timer not found** ERRNO: N/A*/LOCAL STATUS dot11TimerOpDel    (    DOT11_TIMER_REQ * pReq       /* Request structure */    )    {    DOT11_TIMER * pBug;    DOT11_TIMER * pLast;    if (dot11TimerUsage == 0)        {        DOT11_TIMER_LOG("dot11TimerOpDel: Not init\n",0,0,0,0,0,0);        return ERROR;        }        DOT11_TIMER_LOG("dot11TimerOpDel: Deleting %d\n",pReq->timerId,0,0,0,0,0);       /* Check the special case where the head is the match */    if ((dot11TimerLib.pHead != NULL) &&         (dot11TimerLib.pHead->timerId == pReq->timerId))        {        pLast = dot11TimerLib.pHead;        dot11TimerLib.pHead = dot11TimerLib.pHead->pNext;        DOT11_TIMER_FREE((char*)pLast);        }    else        {        pBug = pLast = dot11TimerLib.pHead;                /* Search for your particular timerId */        while ((pBug != NULL) && (pBug->timerId != pReq->timerId))            {            pLast = pBug;            pBug = pBug->pNext;            }        /* See if we found a match or exited because we hit the end of the        LL */        if (pBug != NULL)            {            pLast->pNext = pBug->pNext;            DOT11_TIMER_FREE((char*)pBug);            }        else            {            DOT11_TIMER_LOG("dot11TimerOpDel: TimerId %d not found\n",                            pReq->timerId,0,0,0,0,0);                        }        }    return OK;    }/***************************************************************************** dot11TimerFlush - Deletes all pending timers ** This routine is used to clear all currently waiting timers on the timer* list. ** RETURNS: none** ERRNO: N/A*/LOCAL STATUS dot11TimerFlush()    {    DOT11_TIMER * pBug;    DOT11_TIMER * pLast;        DOT11_TIMER_LOG("dot11TimerFlush: flushing\n",0,0,0,0,0,0);        pBug = pLast = dot11TimerLib.pHead;        while (pBug != NULL)        {        pLast = pBug;        pBug = pBug->pNext;        DOT11_TIMER_FREE((char*)pLast);        }        dot11TimerLib.pHead = NULL;    return OK;    }/***************************************************************************** dot11TimerCalloc - Allocates and clears a block of memory from the * libraries private memory pool.** This routine attempts to allocate a block of memory from the * dot11TimerLibs private memory pool. On success the block is cleared and * the allocation success state variable is incremented. On failure the * the allocation error state variable is incremented. Once the above * operations are complete a pointer to the memory block is returned to* the callee.** RETURNS: * a reference to a valid memory block on success, else NULL on error.** ERRNO: N/A*/LOCAL void* dot11TimerCalloc    (    size_t elemNum,  /* Number of elements to clear */    size_t elemSize  /* Size of each element */    )    {    void*  pBlock;    size_t nBytes = (size_t)(elemNum*elemSize);    /* Allocate a buffer from the memory partition */    if ((pBlock = memPartAlloc(dot11TimerLib.memPart->id,                               (UINT32)nBytes))        != NULL)        {        /* Clear the allocated buffer */        (void)memset(pBlock, 0, nBytes);        /* For each allocation success update the statistics         counter */        dot11TimerLib.memPart->allocSuccess++;        }    else        {        /* For each allocation error update the statistics         counter */        dot11TimerLib.memPart->allocError++;        }    /* Return the reference to the callee */    return(pBlock);    }/***************************************************************************** dot11TimerFree - Releases a block of memory to the libraries private* memory pool. ** This routine attempts to deallocate a block of memory from the* dot11TimerLibs private memory pool. On success the dealloction success * state variable is incremented. On failure the the dealloction error state * variable is incremented. Once the above operations are complete a status* value of ERROR or SUCCESS is returned to the callee.** RETURNS: * SUCCESS on successful deallocation, else ERROR.** ERRNO: N/A*/LOCAL STATUS dot11TimerFree    (    char* pBlock /* Reference to an allocated memory block */    )    {    STATUS retVal;    /* Attempt to free the allocated block */    if ((retVal = memPartFree(dot11TimerLib.memPart->id, pBlock))        == ERROR)        {        /* For each deallocation error update the statistics         counter */        dot11TimerLib.memPart->freeError++;        }    else        {        /* For each deallocation success update the statistics         counter */        dot11TimerLib.memPart->freeSuccess++;        }        /* Reclaim the allocated block */    return(retVal);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -