1 /**************************************************************************** 2 * 3 * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. 4 * Author: Gregory Nutt <gnutt@nuttx.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the 15 * distribution. 16 * 3. Neither the name NuttX nor the names of its contributors may be 17 * used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 * 33 ****************************************************************************/ 34 35 #ifndef __INCLUDE_QUEUE_H 36 #define __INCLUDE_QUEUE_H 37 38 /**************************************************************************** 39 * Included Files 40 ****************************************************************************/ 41 42 #include <sys/types.h> 43 44 /**************************************************************************** 45 * Pre-processor Definitions 46 ****************************************************************************/ 47 48 #define sq_init(q) do { (q)->head = NULL; (q)->tail = NULL; } while (0) 49 #define dq_init(q) do { (q)->head = NULL; (q)->tail = NULL; } while (0) 50 51 #define sq_next(p) ((p)->flink) 52 #define dq_next(p) ((p)->flink) 53 #define dq_prev(p) ((p)->blink) 54 55 #define sq_empty(q) ((q)->head == NULL) 56 #define dq_empty(q) ((q)->head == NULL) 57 58 #define sq_peek(q) ((q)->head) 59 #define dq_peek(q) ((q)->head) 60 61 /**************************************************************************** 62 * Public Type Definitions 63 ****************************************************************************/ 64 65 struct sq_entry_s 66 { 67 struct sq_entry_s *flink; 68 }; 69 typedef struct sq_entry_s sq_entry_t; 70 71 struct dq_entry_s 72 { 73 struct dq_entry_s *flink; 74 struct dq_entry_s *blink; 75 }; 76 typedef struct dq_entry_s dq_entry_t; 77 78 struct sq_queue_s 79 { 80 sq_entry_t *head; 81 sq_entry_t *tail; 82 }; 83 typedef struct sq_queue_s sq_queue_t; 84 85 struct dq_queue_s 86 { 87 dq_entry_t *head; 88 dq_entry_t *tail; 89 }; 90 typedef struct dq_queue_s dq_queue_t; 91 92 /**************************************************************************** 93 * Public Function Prototypes 94 ****************************************************************************/ 95 96 #ifdef __cplusplus 97 #define EXTERN extern "C" 98 extern "C" 99 { 100 #else 101 #define EXTERN extern 102 #endif 103 104 void sq_addfirst(sq_entry_t *node, sq_queue_t *queue); 105 void dq_addfirst(dq_entry_t *node, dq_queue_t *queue); 106 void sq_addlast(sq_entry_t *node, sq_queue_t *queue); 107 void dq_addlast(dq_entry_t *node, dq_queue_t *queue); 108 void sq_addafter(sq_entry_t *prev, sq_entry_t *node, 109 sq_queue_t *queue); 110 void dq_addafter(dq_entry_t *prev, dq_entry_t *node, 111 dq_queue_t *queue); 112 void dq_addbefore(dq_entry_t *next, dq_entry_t *node, 113 dq_queue_t *queue); 114 115 sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue); 116 void sq_rem(sq_entry_t *node, sq_queue_t *queue); 117 void dq_rem(dq_entry_t *node, dq_queue_t *queue); 118 sq_entry_t *sq_remlast(sq_queue_t *queue); 119 dq_entry_t *dq_remlast(dq_queue_t *queue); 120 sq_entry_t *sq_remfirst(sq_queue_t *queue); 121 dq_entry_t *dq_remfirst(dq_queue_t *queue); 122 123 #undef EXTERN 124 #ifdef __cplusplus 125 } 126 #endif 127 128 #endif /* __INCLUDE_QUEUE_H_ */ 129