1#ifndef _u2ec_list_h_ 2#define _u2ec_list_h_ 3 4#ifdef __cplusplus 5extern "C" { 6#endif 7 8struct u2ec_list_head 9{ 10 struct u2ec_list_head *next, *prev; 11}; 12 13#define U2EC_LIST_HEAD(_name) struct u2ec_list_head _name = {&_name, &_name} 14#define U2EC_INIT_LIST(_ptr) do{ (_ptr)->next = (_ptr); (_ptr)->prev = (_ptr); }while(0) 15 16#define U2EC_LIST_ADD(_new, _prev, _next) do{ \ 17 (_new)->prev = (_prev); \ 18 (_new)->next = (_next); \ 19 (_prev)->next = (_new); \ 20 (_next)->prev = (_new); \ 21}while(0) 22 23#define U2EC_LIST_DEL(_del) do{ \ 24 (_del)->prev->next = (_del)->next; \ 25 (_del)->next->prev = (_del)->prev; \ 26 (_del)->prev = (struct u2ec_list_head *)0;\ 27 (_del)->next = (struct u2ec_list_head *)0;\ 28}while(0) 29 30#define u2ec_list_for_each(_pos, _head) \ 31 for (_pos = (_head)->next; \ 32 _pos != (_head); \ 33 _pos = (_pos)->next) 34 35#define u2ec_list_for_each_safe(_pos, n, _head) \ 36 for (_pos = (_head)->next, n = (_pos)->next; \ 37 _pos != (_head); \ 38 _pos = n, n = (_pos)->next) 39 40static void inline u2ec_list_add_tail(struct u2ec_list_head *tail, struct u2ec_list_head *head) 41{ 42 U2EC_LIST_ADD(tail, head->prev, head); 43} 44 45static void inline u2ec_list_del(struct u2ec_list_head *del) 46{ 47 U2EC_LIST_DEL(del); 48} 49 50static int inline u2ec_list_empty(struct u2ec_list_head *h) 51{ 52 return h->next == h; 53} 54 55#ifdef __cplusplus 56} 57#endif 58 59#endif 60