xref: /freebsd/contrib/ntp/include/ntp_prio_q.h (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
1 /* ntp_prio_q.h
2  *
3  * This file contains the structures and function prototypes for the
4  * priority queue implementation used by the discrete event simulator.
5  *
6  * Written By:	Sachin Kamboj
7  *		University of Delaware
8  *		Newark, DE 19711
9  * Copyright (c) 2006
10  */
11 
12 #ifndef NTP_PRIO_Q_H
13 #define NTP_PRIO_Q_H
14 
15 #include <stddef.h>		/* size_t */
16 
17 /* Structures for storing a priority queue
18  * ---------------------------------------
19  */
20 
21 typedef struct node {
22 	union {
23 		struct node *next;
24 		double d;
25 	} nodeu;
26 } node;
27 #define node_next nodeu.next
28 
29 typedef int (*q_order_func)(const void *, const void *);
30 
31 typedef struct Queue {
32 	q_order_func	get_order;
33 	node *		front;
34 	int		no_of_elements;
35 } queue;
36 
37 
38 /* FUNCTION PROTOTYPES
39  * -------------------
40  */
41 /* Define a function to create a FIFO queue */
42 #define create_queue()	create_priority_queue(&get_fifo_order)
43 
44 void destroy_queue(queue *my_queue);
45 void free_node(void *my_node);
46 void *next_node(void *my_node);
47 int empty(queue *my_queue);
48 void *queue_head(queue *my_queue);
49 queue *enqueue(queue *my_queue, void *my_node);
50 void append_queue(queue *q1, queue *q2);
51 void *dequeue(queue *my_queue);
52 int get_no_of_elements(queue *my_queue);
53 int get_fifo_order(const void *el1, const void *el2);
54 
55 /*
56  * Preserve original callsite __FILE__ and __LINE__ for these
57  * malloc-like funcs when using MS C runtime debug heap.
58  */
59 #ifdef _CRTDBG_MAP_ALLOC
60 # define create_priority_queue(order)	debug_create_priority_queue(order, __FILE__, __LINE__)
61 # define get_node(size)			debug_get_node(size, __FILE__, __LINE__)
62 #else
63 # define create_priority_queue(order)	debug_create_priority_queue(order)
64 # define get_node(size)			debug_get_node(size)
65 #endif
66 
67 queue *debug_create_priority_queue(
68 	q_order_func	get_order
69 #ifdef _CRTDBG_MAP_ALLOC
70 	, const char *	sourcefile
71 	, int		line_num
72 #endif
73 	);
74 
75 void *debug_get_node(
76 	size_t		size
77 #ifdef _CRTDBG_MAP_ALLOC
78 	, const char *	sourcefile
79 	, int		line_num
80 #endif
81 	);
82 
83 #endif	/* NTP_PRIO_Q_H */
84