[164] | 1 | /*
|
---|
| 2 | * TOPPERS Software
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2000 by Embedded and Real-Time Systems Laboratory
|
---|
| 6 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 7 | * Copyright (C) 2006-2011 by Embedded and Real-Time Systems Laboratory
|
---|
| 8 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 9 | *
|
---|
| 10 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
| 11 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
| 12 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
| 13 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
| 14 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
| 15 | * XR[hÉÜÜêÄ¢é±ÆD
|
---|
| 16 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
| 17 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
| 18 | gip
|
---|
| 19 | * Ò}j
|
---|
| 20 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
| 21 | * ̳ÛØKèðfÚ·é±ÆD
|
---|
| 22 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
| 23 | * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
| 24 | * ÆD
|
---|
| 25 | * (a) Äzzɺ¤hL
|
---|
| 26 | gipÒ}j
|
---|
| 27 | AÈÇjÉCãLÌ
|
---|
| 28 | * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
| 29 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
| 30 | * ñ·é±ÆD
|
---|
| 31 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
| 32 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
| 33 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
| 34 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
| 35 | * ÆÓ·é±ÆD
|
---|
| 36 | *
|
---|
| 37 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
| 38 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
| 39 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
| 40 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
| 41 | * ÌÓCðíÈ¢D
|
---|
| 42 | *
|
---|
| 43 | * @(#) $Id: queue.h 164 2016-03-07 11:33:50Z coas-nagasima $
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * L
|
---|
| 48 | [ìCu
|
---|
| 49 | *
|
---|
| 50 | * ±ÌL
|
---|
| 51 | [ìCuÅÍCL
|
---|
| 52 | [wb_ðÜÞO\¢Ì_u
|
---|
| 53 | * NL
|
---|
| 54 | [ðµ¤DïÌIÉÍCL
|
---|
| 55 | [wb_ÌGgÍL
|
---|
| 56 | [Ì
|
---|
| 57 | * æªÌGgCOGgÍL
|
---|
| 58 | [ÌöÌGgÆ·éDܽCL
|
---|
| 59 | *
|
---|
| 60 | [ÌæªÌGgÌOGgÆCL
|
---|
| 61 | [ÌöÌGgÌG
|
---|
| 62 | * gÍCL
|
---|
| 63 | [wb_Æ·éDóÌL
|
---|
| 64 | [ÍCGgCOGgÆ
|
---|
| 65 | * ੪©gðw·L
|
---|
| 66 | [wb_Å çí·D
|
---|
| 67 | */
|
---|
| 68 |
|
---|
| 69 | #ifndef TOPPERS_QUEUE_H
|
---|
| 70 | #define TOPPERS_QUEUE_H
|
---|
| 71 |
|
---|
| 72 | #ifdef __cplusplus
|
---|
| 73 | extern "C" {
|
---|
| 74 | #endif
|
---|
| 75 |
|
---|
| 76 | /*
|
---|
| 77 | * L
|
---|
| 78 | [Ìf[^\¢Ìè`
|
---|
| 79 | */
|
---|
| 80 | typedef struct queue {
|
---|
| 81 | struct queue *p_next; /* GgÖÌ|C^ */
|
---|
| 82 | struct queue *p_prev; /* OGgÖÌ|C^ */
|
---|
| 83 | } QUEUE;
|
---|
| 84 |
|
---|
| 85 | /*
|
---|
| 86 | * L
|
---|
| 87 | [Ìú»
|
---|
| 88 | *
|
---|
| 89 | * p_queueÉÍL
|
---|
| 90 | [wb_ðwè·éD
|
---|
| 91 | */
|
---|
| 92 | Inline void
|
---|
| 93 | queue_initialize(QUEUE *p_queue)
|
---|
| 94 | {
|
---|
| 95 | p_queue->p_prev = p_queue;
|
---|
| 96 | p_queue->p_next = p_queue;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /*
|
---|
| 100 | * L
|
---|
| 101 | [ÌOGgÖÌ}ü
|
---|
| 102 | *
|
---|
| 103 | * p_queueÌOÉp_entryð}ü·éDp_queueÉL
|
---|
| 104 | [wb_ðwèµ½ê
|
---|
| 105 | * ÉÍCL
|
---|
| 106 | [ÌöÉp_entryð}ü·é±ÆÉÈéD
|
---|
| 107 | */
|
---|
| 108 | Inline void
|
---|
| 109 | queue_insert_prev(QUEUE *p_queue, QUEUE *p_entry)
|
---|
| 110 | {
|
---|
| 111 | p_entry->p_prev = p_queue->p_prev;
|
---|
| 112 | p_entry->p_next = p_queue;
|
---|
| 113 | p_queue->p_prev->p_next = p_entry;
|
---|
| 114 | p_queue->p_prev = p_entry;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /*
|
---|
| 118 | * L
|
---|
| 119 | [ÌGgÖÌ}ü
|
---|
| 120 | *
|
---|
| 121 | * p_queueÌÉp_entryð}ü·éDp_queueÉL
|
---|
| 122 | [wb_ðwèµ½ê
|
---|
| 123 | * ÉÍCL
|
---|
| 124 | [ÌæªÉp_entryð}ü·é±ÆÉÈéD
|
---|
| 125 | */
|
---|
| 126 | Inline void
|
---|
| 127 | queue_insert_next(QUEUE *p_queue, QUEUE *p_entry)
|
---|
| 128 | {
|
---|
| 129 | p_entry->p_prev = p_queue;
|
---|
| 130 | p_entry->p_next = p_queue->p_next;
|
---|
| 131 | p_queue->p_next->p_prev = p_entry;
|
---|
| 132 | p_queue->p_next = p_entry;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | /*
|
---|
| 136 | * GgÌí
|
---|
| 137 | *
|
---|
| 138 | * p_entryðL
|
---|
| 139 | [©çí·éD
|
---|
| 140 | */
|
---|
| 141 | Inline void
|
---|
| 142 | queue_delete(QUEUE *p_entry)
|
---|
| 143 | {
|
---|
| 144 | p_entry->p_prev->p_next = p_entry->p_next;
|
---|
| 145 | p_entry->p_next->p_prev = p_entry->p_prev;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | /*
|
---|
| 149 | * L
|
---|
| 150 | [Ìñ
|
---|
| 151 | *
|
---|
| 152 | * øp_topðL
|
---|
| 153 | [Æ·éGgð檩çñ·éB
|
---|
| 154 | * ÅÌÄoµÅÍAp_entryÉNULLðn·BÔlÍp_topÌÌGg(ÂÜèæª)Å éB
|
---|
| 155 | * ñÈ~ÍOñɾ½Ggðp_entryÉn·BÔlÍp_entryÌÌGgÆÈéB
|
---|
| 156 | * p_entryÌÌGgªp_top¾Á½Æ«ANULLðÔlƵÄAL
|
---|
| 157 | [ÌI[ð çí·B
|
---|
| 158 | * p_topÌNULL`FbNâp_entryÌëØÍsÁĢȢBÄoµ¤ÌÓCÅs¤±ÆB
|
---|
| 159 | * ܽA¾¤ÜÅàÈ¢ªAXbhZ[tÉÍÈè¦È¢Bñ[vÍr¼Í
|
---|
| 160 | * Äoµ¤ÌÓCÅs¤±ÆB
|
---|
| 161 | */
|
---|
| 162 | Inline QUEUE *
|
---|
| 163 | queue_enumerate(QUEUE *p_top, QUEUE *p_entry)
|
---|
| 164 | {
|
---|
| 165 | QUEUE *p_result;
|
---|
| 166 | if (p_entry == NULL) {
|
---|
| 167 | p_result = p_top->p_next;
|
---|
| 168 | } else {
|
---|
| 169 | p_result = p_entry->p_next;
|
---|
| 170 | }
|
---|
| 171 | if (p_result == p_top) {
|
---|
| 172 | return NULL;
|
---|
| 173 | }
|
---|
| 174 | return p_result;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | /*
|
---|
| 178 | * L
|
---|
| 179 | [ÌGgÌæoµ
|
---|
| 180 | *
|
---|
| 181 | * p_queueÌGgðL
|
---|
| 182 | [©çíµCíµ½GgðÔ·D
|
---|
| 183 | * p_queueÉL
|
---|
| 184 | [wb_ðwèµ½êÉÍCL
|
---|
| 185 | [ÌæªÌGgð
|
---|
| 186 | * æèo·±ÆÉÈéDp_queueÉóÌL
|
---|
| 187 | [ðwèµÄÄÑoµÄÍÈç
|
---|
| 188 | * ȢD
|
---|
| 189 | */
|
---|
| 190 | Inline QUEUE *
|
---|
| 191 | queue_delete_next(QUEUE *p_queue)
|
---|
| 192 | {
|
---|
| 193 | QUEUE *p_entry;
|
---|
| 194 |
|
---|
| 195 | assert(p_queue->p_next != p_queue);
|
---|
| 196 | p_entry = p_queue->p_next;
|
---|
| 197 | p_queue->p_next = p_entry->p_next;
|
---|
| 198 | p_entry->p_next->p_prev = p_queue;
|
---|
| 199 | return(p_entry);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | /*
|
---|
| 203 | * L
|
---|
| 204 | [ÌGgÌ|C^ðæ¾
|
---|
| 205 | *
|
---|
| 206 | * p_queue ÌGgðÔ·Dp_queue ÉL
|
---|
| 207 | [wb_ðwèµ½êÉÍC
|
---|
| 208 | * L
|
---|
| 209 | [ÌæªÌGgðæèo·±ÆÉÈéDp_queue ÉóÌL
|
---|
| 210 | [ð
|
---|
| 211 | * wèµÄÄÑoµÄÍÈçÈ¢D
|
---|
| 212 | */
|
---|
| 213 | Inline QUEUE *
|
---|
| 214 | queue_peek_next(QUEUE *p_queue)
|
---|
| 215 | {
|
---|
| 216 | assert(p_queue->p_next != p_queue);
|
---|
| 217 |
|
---|
| 218 | return(p_queue->p_next);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | /*
|
---|
| 222 | * L
|
---|
| 223 | [ªó©Ç¤©Ì`FbN
|
---|
| 224 | *
|
---|
| 225 | * p_queueÉÍL
|
---|
| 226 | [wb_ðwè·éD
|
---|
| 227 | */
|
---|
| 228 | Inline bool_t
|
---|
| 229 | queue_empty(QUEUE *p_queue)
|
---|
| 230 | {
|
---|
| 231 | if (p_queue->p_next == p_queue) {
|
---|
| 232 | assert(p_queue->p_prev == p_queue);
|
---|
| 233 | return(true);
|
---|
| 234 | }
|
---|
| 235 | return(false);
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | #ifdef __cplusplus
|
---|
| 239 | }
|
---|
| 240 | #endif
|
---|
| 241 |
|
---|
| 242 | #endif /* TOPPERS_QUEUE_H */
|
---|