queue.h
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:3k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  *  include/asm-s390/queue.h
  3.  *
  4.  *  S390 version
  5.  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6.  *    Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
  7.  *
  8.  *  A little set of queue utilies.
  9.  */
  10. #ifndef __ASM_QUEUE_H
  11. #define __ASM_QUEUE_H
  12. #include <linux/stddef.h>
  13. typedef struct queue
  14. {
  15. struct queue *next;
  16. } queue;
  17. typedef queue list;
  18. typedef struct
  19. {
  20. queue *head;
  21. queue *tail;
  22. } qheader;
  23. static __inline__ void init_queue(qheader *qhead)
  24. {
  25. memset(qhead,0,sizeof(*qhead));
  26. }
  27. static __inline__ void enqueue_tail(qheader *qhead,queue *member)
  28. {
  29. if(member)
  30. {
  31. queue *tail=qhead->tail;
  32. if(tail)
  33. tail->next=member;
  34. else
  35. qhead->head=member;
  36. qhead->tail=member;
  37. member->next=NULL;
  38. }
  39. static __inline__ queue *dequeue_head(qheader *qhead)
  40. {
  41. queue *head=qhead->head,*next_head;
  42. if(head)
  43. {
  44. next_head=head->next;
  45. qhead->head=next_head;
  46.         if(!next_head)
  47. qhead->tail=NULL;
  48. }
  49. return(head);
  50. }
  51. static __inline__ void init_list(list **lhead)
  52. {
  53. *lhead=NULL;
  54. }
  55. static __inline__ void add_to_list(list **lhead,list *member)
  56. {
  57. member->next=*lhead;
  58. *lhead=member;
  59. }
  60. static __inline__ list *remove_listhead(list **lhead)
  61. {
  62. list *oldhead=*lhead;
  63. if(oldhead)
  64. *lhead=(*lhead)->next;
  65. return(oldhead);
  66. }
  67. static __inline__ void add_to_list_tail(list **lhead,list *member)
  68. {
  69. list *curr,*prev;
  70. if(*lhead==NULL)
  71. *lhead=member;
  72. else
  73. {
  74. prev=*lhead;
  75. for(curr=(*lhead)->next;curr!=NULL;curr=curr->next)
  76. prev=curr;
  77. prev->next=member;
  78. }
  79. }
  80. static __inline__ void add_to_list_tail_null(list **lhead,list *member)
  81. {
  82. member->next=NULL;
  83. add_to_list_tail_null(lhead,member);
  84. }
  85. static __inline__ int is_in_list(list *lhead,list *member)
  86. {
  87. list *curr;
  88. for(curr=lhead;curr!=NULL;curr=curr->next)
  89. if(curr==member)
  90. return(1);
  91. return(0);
  92. }
  93. static __inline__ int get_prev(list *lhead,list *member,list **prev)
  94. {
  95. list *curr;
  96. *prev=NULL;
  97. for(curr=lhead;curr!=NULL;curr=curr->next)
  98. {
  99. if(curr==member)
  100. return(1);
  101. *prev=curr;
  102. }
  103. *prev=NULL;
  104. return(0);
  105. }
  106. static __inline__ int remove_from_list(list **lhead,list *member)
  107. {
  108. list *prev;
  109. if(get_prev(*lhead,member,&prev))
  110. {
  111. if(prev)
  112. prev->next=member->next;
  113. else
  114. *lhead=member->next;
  115. return(1);
  116. }
  117. return(0);
  118. }
  119. static __inline__ int remove_from_queue(qheader *qhead,queue *member)
  120. {
  121. queue *prev;
  122. if(get_prev(qhead->head,(list *)member,(list **)&prev))
  123. {
  124. if(prev)
  125. {
  126. prev->next=member->next;
  127. if(prev->next==NULL)
  128. qhead->tail=prev;
  129. }
  130. else
  131. {
  132. if(qhead->head==qhead->tail)
  133. qhead->tail=NULL;
  134. qhead->head=member->next;
  135. }
  136. return(1);
  137. }
  138. return(0);
  139. }
  140. #endif /* __ASM_QUEUE_H */