• 博客访问： 91175
• 博文数量： 31
• 博客积分： 0
• 博客等级： 民兵
• 技术积分： 380
• 用 户 组： 普通用户
• 注册时间： 2014-02-24 22:04

2014年（31）

2014-05-26 10:40:45

SIMPLEQ队列图例：

1. /*
2.  * Simple queue definitions.
3.  */
5. struct name {                                \
6.     struct type *sqh_first;    /* first element */            \
7.     struct type **sqh_last;    /* addr of last next element */        \
8. }

struct event_list{
struct event *sqh_first;
struct event **sqh_last;
}

sqh_first指向SIMPLEQ的第一个元素，而sqh_last指向SIMPLEQ的最后一个元素

1. #define SIMPLEQ_ENTRY(type)                        \
2. struct {                                \
3.     struct type *sqe_next;    /* next element */            \
4. }

struct {
struct event *sqe_next;
}

1. /*
2.  * Simple queue access methods.
3.  */

1. #define    SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)

1. #define SIMPLEQ_FOREACH(var, head, field)                \
4.      (var) = SIMPLEQ_NEXT(var, field))

(var) = SIMPLEQ_NEXT(var, field))
SIMPLEQ_FOREACH(pTmp,&pEventBase->eventquue,event_next)
for((pTmp) = SIMPLEQ_FIRST(&pEventBase->eventqueue);
(pTmp) != NULL；
(pTmp) = SIMPLE_NEXT(pTmp,event_next))

for((pTmp) = ((&pEventBase->eventqueue)->sqh_first);
(pTmp) != NULL；
(pTmp) = ((pTmp)->event_next.sqe_next)  )

1. /*
2.  * Simple queue functions.
3.  */
4. #define    SIMPLEQ_INIT(head) do {                        \
7. } while (0)

do{
(&pEventBase->eventqueue)->sqh_first = NULL;    //让头节点的first指针指向NULL
(&pEventBase->eventqueue)->sqh_last = &(&pEventBase->eventqueue)->sqh_first；    //让头节点的last指针指向头节点的first指针
}

3.         (head)->sqh_last = &(elm)->field.sqe_next;        \ //
5. } while (0)

1. #define SIMPLEQ_INSERT_TAIL(head, elm, field) do {            \在SIMPLEQ尾部插入一个元素
2.     (elm)->field.sqe_next = NULL;                    \
5. } while (0)

1. (elm)->field.sqe_next = NULL;                    //让elm的next指针指向NULL

1. #define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do {        \    //在listelm后插入elm
2.     if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
4.     (listelm)->field.sqe_next = (elm);                \
5. } while (0)

1. ((elm)->field.sqe_next = (listelm)->field.sqe_next)    //让elm的next指针指向listelm的next指针
3. (listelm)->field.sqe_next = (elm);                   //让listelm的next指针指向elm所指元素

2.     if (((head)->sqh_first = (elm)->field.sqe_next) == NULL)    \
4. } while (0)

0