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

📄 windlib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
* Remove task from the delay queue and return to it ERROR.** RETURNS: OK** NOMANUAL*/STATUS windUndelay    (    WIND_TCB *pTcb    )    {    if ((pTcb->status & WIND_DELAY) == 0)	/* in not delayed then done */	return (OK);#ifdef WV_INSTRUMENTATION    /* windview - level 2 event logging */    EVT_TASK_1 (EVENT_WINDUNDELAY, (int) pTcb); 	/* log event */#endif    pTcb->status &= ~WIND_DELAY;		/* undelay status */    Q_REMOVE (&tickQHead, &pTcb->tickNode);	/* remove from tick queue */    taskRtnValueSet (pTcb, ERROR);		/* return ERROR */    pTcb->errorStatus = S_taskLib_TASK_UNDELAYED;    if (pTcb->status == WIND_READY)		/* if ready, enqueue */	Q_PUT (&readyQHead, pTcb, pTcb->priority);    return (OK);    }/********************************************************************************* windWdStart - start a watchdog timer** This routine will start or restart a watchdog.  If the watchdog is already* in the queue, it is resorted to the appropriate timeout.  If there are* more windWdStart() jobs still in the kernel work queue, as counted by the* variable deferStartCnt, then no action is taken.** RETURNS: OK.** NOMANUAL*/STATUS windWdStart    (    WDOG *wdId,         /* watch dog to start */    int   timeout       /* timeout in ticks */    )    {    int deferStartCnt;	/* temp variable to hold deferStartCnt */    int level; #ifdef WV_INSTRUMENTATION    /* windview - level 2 event logging */    EVT_TASK_1 (EVENT_WINDWDSTART, (int) wdId); 	/* log event */#endif    /* Protect the decrement from interrupts to avoid the race condition       that spr 7070 describes */    level = intLock ();	deferStartCnt = -- wdId->deferStartCnt;    intUnlock (level);    if (deferStartCnt == 0)	{	if ((unsigned)(vxTicks + timeout) < vxTicks)	/* rollover? */	    {	    Q_CALIBRATE (&tickQHead, ~vxTicks + 1);	    vxTicks = 0;	    }	if (wdId->status == WDOG_IN_Q)			/* resort if in queue */	    Q_RESORT (&tickQHead, &wdId->tickNode, timeout + vxTicks);	else	    Q_PUT (&tickQHead, &wdId->tickNode, timeout + vxTicks);	wdId->status = WDOG_IN_Q;	}    return (OK);    }/********************************************************************************* windWdCancel - cancel a watchdog timer** This routine cancels a watchdog, removing it from the timer queue if needed.** NOMANUAL*/void windWdCancel    (    WDOG *wdId          /* watch dog to cancel */    )    {#ifdef WV_INSTRUMENTATION    /* windview - level 2 event logging */    EVT_TASK_1 (EVENT_WINDWDCANCEL, (int) wdId); 	/* log event */#endif     if (wdId->status == WDOG_IN_Q)	{	Q_REMOVE (&tickQHead, &wdId->tickNode);	/* remove from queue */	wdId->status = WDOG_OUT_OF_Q;	}    }/********************************************************************************* windPendQGet - remove and next task on pend queue and make ready** Take the next task on the specified pend queue and unpend it.  It will either* be ready or suspended.  If ready it is added to the ready queue.** NOMANUAL*/void windPendQGet    (    Q_HEAD *pQHead      /* pend queue to get first task off */    )    {    FAST WIND_TCB *pTcb = (WIND_TCB *) Q_GET (pQHead);#ifdef WV_INSTRUMENTATION    /* windview - level 2 event logging */    EVT_TASK_1 (EVENT_WINDPENDQGET, (int) pTcb); 	/* log event */#endif    pTcb->status &= ~WIND_PEND;			/* clear pended flag */    taskRtnValueSet (pTcb, OK);			/* return OK */    if (pTcb->status & WIND_DELAY)		/* task was timing out */	{	pTcb->status &= ~WIND_DELAY;	Q_REMOVE (&tickQHead, &pTcb->tickNode);	/* remove from queue */	}    if (pTcb->status == WIND_READY)		/* task is now ready */	Q_PUT (&readyQHead, pTcb, pTcb->priority);    }/********************************************************************************* windReadyQPut - put a task on the ready queue** This routine adds a task previously blocked on a shared* semaphore to the ready Queue.** The shared TCB of this task has been removed from the shared semaphore* pending queue by the CPU that gives the semaphore.** NOMANUAL*/void windReadyQPut    (    WIND_TCB * pTcb              /* TCB to add to ready Q */    )    {    pTcb->status &= ~WIND_PEND;                 /* clear pended flag */    taskRtnValueSet (pTcb, OK);                 /* return OK */    if (pTcb->status & WIND_DELAY)              /* task was timing out */        {        pTcb->status &= ~WIND_DELAY;        Q_REMOVE (&tickQHead, &pTcb->tickNode); /* remove from queue */        }    if (pTcb->status == WIND_READY)             /* task is now ready */        Q_PUT (&readyQHead, pTcb, pTcb->priority);    }/********************************************************************************* windReadyQRemove - remove pend task from the ready Q** This routines removes the current task from the pend. The task must have* been previously added to a shared semaphore pend Q by using  Q_PUT.* If the task is timing out, also add the task to the delay queue. ** RETURNS: N/A** NOMANUAL*/void windReadyQRemove    (    Q_HEAD *pQHead,        /* pend queue to put taskIdCurrent on */    int    timeout         /* timeout in ticks */    )    {    Q_REMOVE (&readyQHead, taskIdCurrent);              /* out of ready q */    taskIdCurrent->status |= WIND_PEND;                 /* update status */    taskIdCurrent->pPendQ = pQHead;                     /* pQHead pended on */    if (timeout != WAIT_FOREVER)                        /* timeout specified? */        {        if ((unsigned)(vxTicks + timeout) < vxTicks)    /* rollover? */            {            Q_CALIBRATE (&tickQHead, ~vxTicks + 1);            vxTicks = 0;            }        Q_PUT (&tickQHead, &taskIdCurrent->tickNode, timeout + vxTicks);        taskIdCurrent->status |= WIND_DELAY;        }    }/********************************************************************************* windPendQFlush - flush all tasks off of pend queue making them ready** Take all of the tasks on the specified pend queue and unpend them.  They will* either be ready or suspended.  All ready tasks will be added to the ready* queue.** NOMANUAL*/void windPendQFlush    (    Q_HEAD *pQHead      /* pend queue to flush tasks from */    )    {    FAST WIND_TCB *pTcb;#if FALSE#ifdef WV_INSTRUMENTATION    int level = 0;#endif#endif /* FALSE */    while ((pTcb = (WIND_TCB *) Q_GET (pQHead)) != NULL)/* get next task */	{#ifdef WV_INSTRUMENTATION	/* windview - level 2 event logging */	EVT_TASK_1 (EVENT_WINDPENDQFLUSH, (int) pTcb); 	#endif	pTcb->status &= ~WIND_PEND;			/* clear pended flag */	taskRtnValueSet (pTcb, OK);			/* return OK */	if (pTcb->status & WIND_DELAY)			/* task is timeout */	    {	    pTcb->status &= ~WIND_DELAY;	    Q_REMOVE (&tickQHead, &pTcb->tickNode);	/* remove from queue */	    }	if (pTcb->status == WIND_READY)			/* task is now ready */	    Q_PUT (&readyQHead, pTcb, pTcb->priority);	}    }/********************************************************************************* windPendQPut - add current task to a pend queue** Add a taskIdCurrent to a pend queue.  If the task is timing out, also add the* task to the delay queue.  If the NO_WAIT value is passed for a timeout,* return ERROR.** RETURNS: OK, or ERROR if NO_WAIT timeout is specified.** ERRNO: S_objLib_OBJ_UNAVAILABLE** NOMANUAL*/STATUS windPendQPut    (    FAST Q_HEAD *pQHead,        /* pend queue to put taskIdCurrent on */    FAST int    timeout         /* timeout in ticks */    )    {    if (timeout == NO_WAIT)				/* NO_WAIT = no block */	{	errno = S_objLib_OBJ_UNAVAILABLE;		/* resource gone */	return (ERROR);	}#ifdef WV_INSTRUMENTATION    /* windview - level 2 event logging */    EVT_TASK_0 (EVENT_WINDPENDQPUT); 	/* log event */#endif    Q_REMOVE (&readyQHead, taskIdCurrent);		/* out of ready q */    taskIdCurrent->status |= WIND_PEND;			/* update status */    taskIdCurrent->pPendQ = pQHead;			/* pQHead pended on */    Q_PUT (pQHead, taskIdCurrent, taskIdCurrent->priority);    if (timeout != WAIT_FOREVER)			/* timeout specified? */	{	if ((unsigned)(vxTicks + timeout) < vxTicks)	/* rollover? */	    {	    Q_CALIBRATE (&tickQHead, ~vxTicks + 1);	    vxTicks = 0;	    }	Q_PUT (&tickQHead, &taskIdCurrent->tickNode, timeout + vxTicks);	taskIdCurrent->status |= WIND_DELAY;	}    return (OK);    }/********************************************************************************* windPendQRemove - move a task out of the pend queue** This routine removes a task from a pend queue.** RETURNS: OK** NOMANUAL*/STATUS windPendQRemove    (    WIND_TCB *pTcb              /* task to remove from pend queue */    )    {    int status = Q_REMOVE (pTcb->pPendQ, pTcb);	/* out of pend queue */    /*     * When shared semaphore are used Q_REMOVE can return ERROR if lock     * cannot be taken, or ALREADY_REMOVED if the shared tcb is currently     * in the event list, ie removed from the shared semaphore pend Q.     */    pTcb->status   &= ~WIND_PEND;		/* turn off pend bit */    pTcb->pPriMutex = NULL;			/* clear pPriMutex */    if (pTcb->status & WIND_DELAY)		/* task was timing out */	{	pTcb->status &= ~WIND_DELAY;	Q_REMOVE (&tickQHead, &pTcb->tickNode);	/* remove from queue */	}    return (status);    }/********************************************************************************* windPendQTerminate - flush all tasks off of pend queue making them ready** Take all of the tasks on the specified pend queue and unpend them.  They will* either be ready or suspended.  All ready tasks will be added to the ready* queue.  Unlike windPendQFlush (2), this routine returns the ERROR* S_objLib_OBJ_DELETED.** NOMANUAL*/void windPendQTerminate    (    Q_HEAD *pQHead      /* pend queue to terminate */    )    {    FAST WIND_TCB *pTcb;    while ((pTcb = (WIND_TCB *) Q_GET (pQHead)) != NULL)/* get next task */	{#ifdef WV_INSTRUMENTATION        /* windview - level 2 event logging */	EVT_TASK_1 (EVENT_WINDPENDQTERMINATE, (int) pTcb);#endif	pTcb->status     &= ~WIND_PEND;			/* clear pended flag */	pTcb->pPriMutex	  = NULL;			/* clear mutex pend */	pTcb->errorStatus = S_objLib_OBJ_DELETED;	/* set error status */	taskRtnValueSet (pTcb, ERROR);			/* return ERROR */	if (pTcb->status & WIND_DELAY)			/* task is timeout */	    {	    pTcb->status &= ~WIND_DELAY;	    Q_REMOVE (&tickQHead, &pTcb->tickNode);	/* remove from queue */	    }	if (pTcb->status == WIND_READY)			/* task is now ready */	    Q_PUT (&readyQHead, pTcb, pTcb->priority);	}    }

⌨️ 快捷键说明

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