yumapro  20.10-12
YumaPro SDK
dlq.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3  * Copyright (c) 2012 - 2018
4  * Unless required by applicable law or agreed to in writing,
5  * software distributed under the License is distributed on an
6  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
7  * KIND, either express or implied. See the License for the
8  * specific language governing permissions and limitations
9  * under the License.
10  */
11 #ifndef _H_dlq
12 #define _H_dlq
13 /* FILE: dlq.h
14 *********************************************************************
15 * *
16 * P U R P O S E *
17 * *
18 *********************************************************************/
19 
102 /*********************************************************************
103 * *
104 * C H A N G E H I S T O R Y *
105 * *
106 *********************************************************************
107 
108 date init comment
109 ----------------------------------------------------------------------
110 06-jan-89 abb Begun.
111 18-jan-91 abb adapted for depend project
112 12-mar-91 abb adapted for DAVID sbee project
113 14-jun-91 abb changed que.h to dlq.h
114 27-apr-05 abb update docs and use for netconf project
115 15-feb-06 abb make DLQ module const compatible
116  get rid of dlq_hdrPT, as this doesn't work
117  for const pointers.
118 15-sep-06 abb added dlq_swap function
119 26-jan-07 abb added dlq_hdr_t alias for NCX naming conventions
120 12-oct-07 abb add dlq_count
121 */
122 
123 #include "procdefs.h"
124 
125 #ifdef __cplusplus
126 extern "C" {
127 #endif
128 
129 /********************************************************************
130 *
131 * C O N S T A N T S
132 *
133 *********************************************************************/
134 
135 /* que header types */
136 #define DLQ_NULL_NODE 1313
137 #define DLQ_SHDR_NODE 2727
138 #define DLQ_DHDR_NODE 3434
139 #define DLQ_DATA_NODE 5757
140 #define DLQ_DEL_NODE 8686
141 #define DLQ_DEL_DHDR 9696
142 
143 #define dlq_hdr_t dlq_hdrT
144 
145 
146 /********************************************************************
147 *
148 * T Y P E S
149 *
150 *********************************************************************/
151 
155 typedef struct TAGdlq_hdrT
156 {
157  unsigned short hdr_typ;
158  struct TAGdlq_hdrT *prev;
159  struct TAGdlq_hdrT *next;
160 } YPACK dlq_hdrT;
161 
162 
163 /* shorthand macros */
164 #define _hdr_node(P) (((const dlq_hdrT *)(P))->hdr_typ==DLQ_SHDR_NODE \
165  || ((const dlq_hdrT *)(P))->hdr_typ==DLQ_DHDR_NODE)
166 
167 #define _data_node(P) (((const dlq_hdrT *)(P))->hdr_typ==DLQ_DATA_NODE)
168 
169 #define _del_node(P) (((const dlq_hdrT *)(P))->hdr_typ==DLQ_DEL_NODE)
170 
171 
172 #define dlq_hdr_node(P) _hdr_node(P)
173 
174 #define dlq_data_node(P) _data_node(P)
175 
176 
177 #ifdef PTHREADS
178 #define DLQ_HAS_NEXT_NODE(P) (((const dlq_hdrT *)(P))->next)
179 #endif
180 
181 /*
182  * Define enter and exit critical section hooks here:
183  * This was ENTER_FAST_CS but causing crashes with lots of threads
184  */
185 
186 //#define ENTER_CRIT ENTER_FAST_CS
187 //#define EXIT_CRIT EXIT_FAST_CS
188 
189 #define ENTER_CRIT ENTER_CS
190 #define EXIT_CRIT EXIT_CS
191 
192 
193 /********************************************************************
194 *
195 * F U N C T I O N S
196 *
197 *********************************************************************/
198 
199 #ifdef CPP_DEBUG
200 
205 extern void dlq_dumpHdr (const void *nodeP);
206 #endif
207 
208 
215 extern dlq_hdrT * dlq_createQue (void);
216 
217 
223 extern void dlq_createSQue (dlq_hdrT * queAddr);
224 
225 
232 extern void dlq_destroyQue (dlq_hdrT * listP);
233 
234 
242 extern void dlq_enque (REG void *newP, REG dlq_hdrT * listP);
243 
244 
252 extern void *dlq_deque (dlq_hdrT * listP);
253 
254 
262 #if defined(CPP_NO_MACROS)
263 extern void *dlq_nextEntry (const void *nodeP);
264 #else
265 #define dlq_nextEntry(nodeP) (_data_node(((const dlq_hdrT *) (nodeP))->next) ? \
266  ((const dlq_hdrT *) (nodeP))->next : NULL)
267 #endif /* END CPP_NO_MACROS */
268 
269 
277 #if defined(CPP_NO_MACROS)
278 extern void *dlq_prevEntry (const void *nodeP);
279 #else
280 #define dlq_prevEntry(nodeP) (_data_node(((const dlq_hdrT *) (nodeP))->prev ) ? \
281  ((const dlq_hdrT *) (nodeP))->prev : NULL)
282 #endif /* CPP_NO_MACROS */
283 
284 
291 extern void dlq_insertAhead (void *newP, void *nodeP);
292 
293 
300 extern void dlq_insertAfter (void *newP, void *nodeP);
301 
302 
310 extern void dlq_remove (void *nodeP);
311 
312 
324 extern void dlq_swap (void *new_node, void *cur_node);
325 
326 
334 #if defined(CPP_NO_MACROS)
335 extern void *dlq_firstEntry (const dlq_hdrT * listP);
336 #else
337 #define dlq_firstEntry(listP) ((listP) != ((const dlq_hdrT *)(listP))->next ? \
338  ((const dlq_hdrT *)(listP))->next : NULL)
339 #endif /* CPP_NO_MACROS */
340 
341 
349 #if defined(CPP_NO_MACROS)
350 extern void *dlq_lastEntry (const dlq_hdrT * listP);
351 #else
352 #define dlq_lastEntry(listP) ((listP) != ((const dlq_hdrT *)(listP))->next ? \
353  ((const dlq_hdrT *)(listP))->prev : NULL)
354 #endif /* CPP_NO_MACROS */
355 
356 
364 #if defined(CPP_NO_MACROS)
365 extern boolean dlq_empty (const dlq_hdrT * listP);
366 #else
367 #define dlq_empty(listP) (boolean)((listP)==((const dlq_hdrT *)(listP))->next)
368 #endif /* CPP_NO_MACROS */
369 
370 
378 extern void dlq_block_enque (dlq_hdrT * srcP, dlq_hdrT * dstP);
379 
380 
389 extern void dlq_block_insertAhead (dlq_hdrT *srcP, void *dstP);
390 
391 
400 extern void dlq_block_insertAfter (dlq_hdrT *srcP, void *dstP);
401 
402 
415 extern void dlq_block_move (dlq_hdrT *srcQ, void *srcP, dlq_hdrT * dstQ);
416 
417 
424 extern unsigned int dlq_count (const dlq_hdrT *listP);
425 
426 
434 extern boolean dlq_onQueue (const dlq_hdrT *nodeP);
435 
436 
442 extern void dlq_reverse_que (dlq_hdr_t *que);
443 
444 
447 #ifdef __cplusplus
448 } /* end extern 'C' */
449 #endif
450 
451 #endif /* _H_dlq */
ERR_INTERNAL_QDEL
@ ERR_INTERNAL_QDEL
006
Definition: status_enum.h:196
dlq_block_enque
void dlq_block_enque(dlq_hdrT *srcP, dlq_hdrT *dstP)
add all the queue entries in the srcP queue list to the end of the dstP queue list
Definition: dlq.c:731
dlq_insertAfter
void dlq_insertAfter(void *newP, void *nodeP)
insert the new queue entry after the current entry
Definition: dlq.c:482
ERR_QNODE_NOT_DATA
@ ERR_QNODE_NOT_DATA
009
Definition: status_enum.h:199
TAGdlq_hdrT::next
struct TAGdlq_hdrT * next
next header
Definition: dlq.h:163
log_error
void log_error(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_ERROR log entry.
ERR_BAD_QLINK
@ ERR_BAD_QLINK
010
Definition: status_enum.h:200
dlq_lastEntry
#define dlq_lastEntry(listP)
get the last entry in the queue list
Definition: dlq.h:352
dlq_block_move
void dlq_block_move(dlq_hdrT *srcQ, void *srcP, dlq_hdrT *dstQ)
enque from [srcP .
Definition: dlq.c:931
dlq_reverse_que
void dlq_reverse_que(dlq_hdr_t *que)
Reverse the order of all the entries in a Q.
Definition: dlq.c:1070
dlq_insertAhead
void dlq_insertAhead(void *newP, void *nodeP)
insert the new queue entry before the current entry
Definition: dlq.c:447
ERR_QNODE_NOT_HDR
@ ERR_QNODE_NOT_HDR
008
Definition: status_enum.h:198
dlq_block_insertAhead
void dlq_block_insertAhead(dlq_hdrT *srcP, void *dstP)
insert all the entries in the srcP queue list before the dstP queue entry
Definition: dlq.c:800
dlq_swap
void dlq_swap(void *new_node, void *cur_node)
remove the cur_node queue entry from its queue list and replace it with the new_node
Definition: dlq.c:562
TAGdlq_hdrT
dlq header used for both the control block for a queue and also a queue header node within another st...
Definition: dlq.h:155
dlq_createQue
dlq_hdrT * dlq_createQue(void)
create a dynamic queue header
Definition: dlq.c:146
dlq_createSQue
void dlq_createSQue(dlq_hdrT *queAddr)
create a static queue header
Definition: dlq.c:177
ERR_INTERNAL_VAL
@ ERR_INTERNAL_VAL
004
Definition: status_enum.h:194
TAGdlq_hdrT::prev
struct TAGdlq_hdrT * prev
previous header
Definition: dlq.h:162
dlq_remove
void dlq_remove(void *nodeP)
remove the queue entry from its queue list entry MUST have been enqueued somehow before this function...
Definition: dlq.c:519
dlq_onQueue
boolean dlq_onQueue(const dlq_hdrT *nodeP)
Determine where a data node header is on a queue or not.
Definition: dlq.c:1039
ERR_INTERNAL_PTR
@ ERR_INTERNAL_PTR
002
Definition: status_enum.h:192
log_debug
void void void void void void void log_debug(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG log entry.
dlq_count
unsigned int dlq_count(const dlq_hdrT *listP)
get the number of queue entries in the listP queue list
Definition: dlq.c:994
dlq_prevEntry
#define dlq_prevEntry(nodeP)
get the previous queue entry before the current entry
Definition: dlq.h:280
dlq_nextEntry
#define dlq_nextEntry(nodeP)
get the next queue entry after the current entry
Definition: dlq.h:265
TAGdlq_hdrT::hdr_typ
unsigned short hdr_typ
queue header type
Definition: dlq.h:161
log.h
NCX System Logging Manager.
dlq_deque
void * dlq_deque(dlq_hdrT *listP)
remove the first queue node from the queue list
Definition: dlq.c:286
dlq_empty
#define dlq_empty(listP)
check if queue list is empty
Definition: dlq.h:367
dlq_firstEntry
#define dlq_firstEntry(listP)
get the first entry in the queue list
Definition: dlq.h:337
ncx.h
YANG module utility functions.
dlq_enque
void dlq_enque(REG void *newP, REG dlq_hdrT *listP)
add a queue node to the end of a queue list Add newP to listP
Definition: dlq.c:246
dlq_block_insertAfter
void dlq_block_insertAfter(dlq_hdrT *srcP, void *dstP)
insert all the entries in the srcP queue list after the dstP queue entry
Definition: dlq.c:863
dlq_destroyQue
void dlq_destroyQue(dlq_hdrT *listP)
free a dynamic queue header previously allocated with dlq_createQue
Definition: dlq.c:206
status.h
Global error messages for status code enumerations.
dlq.h
dlq provides general double-linked list and queue support: