mtkernel_3/include/sys/queue.h | bare source | permlink (0.00 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * micro T-Kernel 3.00.00 4: * 5: * Copyright (C) 2006-2019 by Ken Sakamura. 6: * This software is distributed under the T-License 2.1. 7: *---------------------------------------------------------------------- 8: * 9: * Released by TRON Forum(http://www.tron.org) at 2019/12/11. 10: * 11: *---------------------------------------------------------------------- 12: */ 13: 14: /* 15: * queue.h 16: * 17: * Queuing operation 18: */ 19: 20: #ifndef __SYS_QUEUE_H__ 21: #define __SYS_QUEUE_H__ 22: 23: #include <tk/tkernel.h> 24: 25: #ifdef __cplusplus 26: extern "C" { 27: #endif 28: 29: /* 30: * Double-link queue (ring) 31: */ 32: typedef struct queue { 33: struct queue *next; 34: struct queue *prev; 35: } QUEUE; 36: 37: /* 38: * Queue initialization 39: */ 40: Inline void QueInit( QUEUE *que ) 41: { 42: que->next = (struct queue *)que; 43: que->prev = (struct queue *)que; 44: } 45: 46: /* 47: * TRUE if the queue is empty 48: */ 49: Inline BOOL isQueEmpty( QUEUE *que ) 50: { 51: return ( que->next == que )? TRUE: FALSE; 52: } 53: 54: /* 55: * Insert in queue 56: * Inserts entry directly prior to que 57: */ 58: Inline void QueInsert( QUEUE *entry, QUEUE *que ) 59: { 60: entry->prev = (struct queue*) que->prev; 61: entry->next = que; 62: que->prev->next = entry; 63: que->prev = entry; 64: } 65: 66: /* 67: * Delete from queue 68: * Deletes entry from queue 69: * No action is performed if entry is empty. 70: */ 71: Inline void QueRemove( QUEUE *entry ) 72: { 73: if ( entry->next != entry ) { 74: entry->prev->next = (struct queue*) entry->next; 75: entry->next->prev = (struct queue*) entry->prev; 76: } 77: } 78: 79: /* 80: * Remove top entry 81: * Deletes the entry directly after que from the queue, 82: * and returns the deleted entry. 83: * Returns NULL if que is empty. 84: */ 85: Inline QUEUE* QueRemoveNext( QUEUE *que ) 86: { 87: QUEUE *entry; 88: 89: if ( que->next == que ) { 90: return NULL; 91: } 92: 93: entry = que->next; 94: que->next = (struct queue*)entry->next; 95: entry->next->prev = que; 96: 97: return entry; 98: } 99: 100: #ifdef __cplusplus 101: } 102: #endif 103: #endif /* __SYS_QUEUE_H__ */