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