Tizen RT Libs&Environment  v1.0 D5
queue.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /****************************************************************************
19  * include/queue.h
20  *
21  * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ****************************************************************************/
60 
63 #ifndef __INCLUDE_QUEUE_H
64 #define __INCLUDE_QUEUE_H
65 
66 /****************************************************************************
67  * Included Files
68  ****************************************************************************/
69 
70 #include <sys/types.h>
71 
72 /****************************************************************************
73  * Pre-processor Definitions
74  ****************************************************************************/
75 
76 #define sq_init(q) do { (q)->head = NULL; (q)->tail = NULL; } while (0)
77 #define dq_init(q) do { (q)->head = NULL; (q)->tail = NULL; } while (0)
78 
79 #define sq_next(p) ((p)->flink)
80 #define dq_next(p) ((p)->flink)
81 #define dq_prev(p) ((p)->blink)
82 
83 #define sq_empty(q) ((q)->head == NULL)
84 #define dq_empty(q) ((q)->head == NULL)
85 
86 #define sq_peek(q) ((q)->head)
87 #define dq_peek(q) ((q)->head)
88 
89 /****************************************************************************
90  * Global Type Declarations
91  ****************************************************************************/
92 
96 struct sq_entry_s {
97  FAR struct sq_entry_s *flink;
98 };
99 typedef struct sq_entry_s sq_entry_t;
100 
104 struct dq_entry_s {
105  FAR struct dq_entry_s *flink;
106  FAR struct dq_entry_s *blink;
107 };
108 typedef struct dq_entry_s dq_entry_t;
109 
113 struct sq_queue_s {
116 };
117 typedef struct sq_queue_s sq_queue_t;
118 
122 struct dq_queue_s {
125 };
126 typedef struct dq_queue_s dq_queue_t;
127 
128 /****************************************************************************
129  * Global Function Prototypes
130  ****************************************************************************/
131 
132 #ifdef __cplusplus
133 #define EXTERN extern "C"
134 extern "C" {
135 #else
136 #define EXTERN extern
137 #endif
138 
146 void sq_addfirst(FAR sq_entry_t *node, FAR sq_queue_t *queue);
154 void dq_addfirst(FAR dq_entry_t *node, FAR dq_queue_t *queue);
162 void sq_addlast(FAR sq_entry_t *node, FAR sq_queue_t *queue);
170 void dq_addlast(FAR dq_entry_t *node, FAR dq_queue_t *queue);
178 void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node, FAR sq_queue_t *queue);
187 void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node, FAR dq_queue_t *queue);
196 void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node, FAR dq_queue_t *queue);
197 
205 FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, FAR sq_queue_t *queue);
213 void sq_rem(FAR sq_entry_t *node, FAR sq_queue_t *queue);
221 void dq_rem(FAR dq_entry_t *node, FAR dq_queue_t *queue);
228 FAR sq_entry_t *sq_remlast(FAR sq_queue_t *queue);
235 FAR dq_entry_t *dq_remlast(FAR dq_queue_t *queue);
242 FAR sq_entry_t *sq_remfirst(FAR sq_queue_t *queue);
249 FAR dq_entry_t *dq_remfirst(FAR dq_queue_t *queue);
250 
251 #undef EXTERN
252 #ifdef __cplusplus
253 }
254 #endif
255 
256 #endif /* __INCLUDE_QUEUE_H_ */
257 // end of QUEUE_LIBC
FAR sq_entry_t * sq_remfirst(FAR sq_queue_t *queue)
removes the first entry from &#39;queue&#39;
FAR sq_entry_t * sq_remlast(FAR sq_queue_t *queue)
Removes the last entry in a singly-linked queue.
structure for singly-linked queue
Definition: queue.h:96
FAR sq_entry_t * head
Definition: queue.h:114
structure for header queue
Definition: queue.h:113
FAR struct dq_entry_s * blink
Definition: queue.h:106
FAR dq_entry_t * dq_remfirst(FAR dq_queue_t *queue)
removes &#39;node&#39; from the head of &#39;queue&#39;
void dq_rem(FAR dq_entry_t *node, FAR dq_queue_t *queue)
removes &#39;node&#39; from &#39;queue&#39;
void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node, FAR sq_queue_t *queue)
adds &#39;node&#39; after &#39;prev&#39; in the &#39;queue.&#39;
FAR dq_entry_t * tail
Definition: queue.h:124
FAR struct sq_entry_s * flink
Definition: queue.h:97
FAR struct dq_entry_s * flink
Definition: queue.h:105
FAR dq_entry_t * head
Definition: queue.h:123
void sq_addlast(FAR sq_entry_t *node, FAR sq_queue_t *queue)
places the &#39;node&#39; at the tail of the &#39;queue&#39;
void sq_rem(FAR sq_entry_t *node, FAR sq_queue_t *queue)
removes a &#39;node&#39; for &#39;queue.&#39;
structure for double-linked queue
Definition: queue.h:104
void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node, FAR dq_queue_t *queue)
adds &#39;node&#39; after &#39;prev&#39; in the &#39;queue.&#39;
void sq_addfirst(FAR sq_entry_t *node, FAR sq_queue_t *queue)
places the &#39;node&#39; at the head of the &#39;queue&#39;
structure for header queue
Definition: queue.h:122
void dq_addfirst(FAR dq_entry_t *node, FAR dq_queue_t *queue)
adds &#39;node&#39; at the beginning of &#39;queue&#39;
FAR sq_entry_t * sq_remafter(FAR sq_entry_t *node, FAR sq_queue_t *queue)
removes the entry following &#39;node
FAR sq_entry_t * tail
Definition: queue.h:115
void dq_addlast(FAR dq_entry_t *node, FAR dq_queue_t *queue)
adds &#39;node&#39; to the end of &#39;queue&#39;
FAR dq_entry_t * dq_remlast(FAR dq_queue_t *queue)
removes the last entry from &#39;queue&#39;
void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node, FAR dq_queue_t *queue)
adds &#39;node&#39; before &#39;next&#39; in &#39;queue&#39;