原创 UCOS-II中消息队列学习笔记(2)

2011-12-7 22:39 1726 17 17 分类: MCU/ 嵌入式

3.删除消息队列

OS_EVENT  *OSQDel (OS_EVENT*pevent, INT8U opt, INT8U *err) reentrant

{

............................................

...........................................

    OS_ENTER_CRITICAL();

    if (pevent->OSEventGrp !=0x00) {                      /* See if any tasks waiting on queue        */

        tasks_waiting =TRUE;                              /*Yes                                     */

    } else {

        tasks_waiting =FALSE;                             /*No                                       */

    }

    switch (opt) {

        case OS_DEL_NO_PEND:                               /* Delete queueonly if no task waiting     */

             if (tasks_waiting ==FALSE) {

//pq放回到消息队列空链表

                 pq                  = pevent->OSEventPtr; /*Return OS_Q to free list                */

                pq->OSQPtr          =OSQFreeList;

                 OSQFreeList         = pq;

             //pevent放回到事件控制块空链表

                pevent->OSEventType = OS_EVENT_TYPE_UNUSED;

                 pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block to freelist  */

                OSEventFreeList     = pevent;             /* Get next free event controlblock        */

                OS_EXIT_CRITICAL();

                 *err = OS_NO_ERR;

                 return((OS_EVENT *)0);                   /*Queue has been deleted                  */

             } else {

                OS_EXIT_CRITICAL();

                 *err =OS_ERR_TASK_WAITING;

                 return (pevent);

             }

 

        case OS_DEL_ALWAYS:                                /* Alwaysdelete the queue                  */

             while(pevent->OSEventGrp != 0x00) {         /* Ready ALL tasks waiting for queue        */

                 OS_EventTaskRdy(pevent,(void *)0, OS_STAT_Q);

             }

             pq                  = pevent->OSEventPtr;     /* Return OS_Q to free list                 */

             pq->OSQPtr          = OSQFreeList;

             OSQFreeList         = pq;

            pevent->OSEventType = OS_EVENT_TYPE_UNUSED;

            pevent->OSEventPtr  =OSEventFreeList;        /* Return EventControl Block to free list  */

             OSEventFreeList     = pevent;                 /* Get next free event controlblock        */

             OS_EXIT_CRITICAL();

             if (tasks_waiting ==TRUE) {                  /* Rescheduleonly if task(s) were waiting  */

                 OS_Sched();                               /* Find highestpriority task ready to run  */

             }

             *err = OS_NO_ERR;

             return ((OS_EVENT*)0);                       /* Queue hasbeen deleted                   */

 

        default:

             OS_EXIT_CRITICAL();

             *err =OS_ERR_INVALID_OPT;

             return (pevent);

    }

}

文章评论0条评论)

登录后参与讨论
我要评论
0
17
关闭 站长推荐上一条 /2 下一条