]> granicus.if.org Git - apache/blob - modules/http2/h2_task_queue.h
merged latest changes in 2.4.x
[apache] / modules / http2 / h2_task_queue.h
1 /* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef __mod_h2__h2_task_queue__
17 #define __mod_h2__h2_task_queue__
18
19 struct h2_task;
20
21 /**
22  * A simple ring of rings that keeps a list of h2_tasks and can
23  * be ringed itself, using the APR RING macros.
24  */
25 typedef struct h2_task_queue h2_task_queue;
26
27 struct h2_task_queue {
28     APR_RING_ENTRY(h2_task_queue) link;
29     APR_RING_HEAD(h2_tasks, h2_task) tasks;
30     long id;
31 };
32
33 /**
34  * Allocate a new queue from the pool and initialize.
35  * @param id the identifier of the queue
36  * @param pool the memory pool
37  */
38 h2_task_queue *h2_tq_create(long id, apr_pool_t *pool);
39
40 /**
41  * Release all queue tasks.
42  * @param q the queue to destroy
43  */
44 void h2_tq_destroy(h2_task_queue *q);
45
46 /**
47  * Return != 0 iff there are no tasks in the queue.
48  * @param q the queue to check
49  */
50 int h2_tq_empty(h2_task_queue *q);
51
52 /**
53  * Append the task to the end of the queue.
54  * @param q the queue to append the task to
55  * @param task the task to append
56   */
57 void h2_tq_append(h2_task_queue *q, struct h2_task *task);
58
59 /**
60  * Remove a task from the queue. Return APR_SUCCESS if the task
61  * was indeed queued, APR_NOTFOUND otherwise.
62  * @param q the queue to remove from
63  * @param task the task to remove
64  */
65 apr_status_t h2_tq_remove(h2_task_queue *q, struct h2_task *task);
66
67 /**
68  * Get the first task from the queue or NULL if the queue is empty. The
69  * task will be removed.
70  * @param q the queue to pop the first task from
71  */
72 h2_task *h2_tq_pop_first(h2_task_queue *q);
73
74 /*******************************************************************************
75  * Queue Manipulation.
76  ******************************************************************************/
77
78 /**
79  * The magic pointer value that indicates the head of a h2_task_queue list
80  * @param  b The queue list
81  * @return The magic pointer value
82  */
83 #define H2_TQ_LIST_SENTINEL(b)  APR_RING_SENTINEL((b), h2_task_queue, link)
84
85 /**
86  * Determine if the queue list is empty
87  * @param b The list to check
88  * @return true or false
89  */
90 #define H2_TQ_LIST_EMPTY(b)     APR_RING_EMPTY((b), h2_task_queue, link)
91
92 /**
93  * Return the first queue in a list
94  * @param b The list to query
95  * @return The first queue in the list
96  */
97 #define H2_TQ_LIST_FIRST(b)     APR_RING_FIRST(b)
98
99 /**
100  * Return the last queue in a list
101  * @param b The list to query
102  * @return The last queue int he list
103  */
104 #define H2_TQ_LIST_LAST(b)      APR_RING_LAST(b)
105
106 /**
107  * Insert a single queue at the front of a list
108  * @param b The list to add to
109  * @param e The queue to insert
110  */
111 #define H2_TQ_LIST_INSERT_HEAD(b, e) do {                               \
112 h2_task_queue *ap__b = (e);                                        \
113 APR_RING_INSERT_HEAD((b), ap__b, h2_task_queue, link);  \
114 } while (0)
115
116 /**
117  * Insert a single queue at the end of a list
118  * @param b The list to add to
119  * @param e The queue to insert
120  */
121 #define H2_TQ_LIST_INSERT_TAIL(b, e) do {                               \
122 h2_task_queue *ap__b = (e);                                     \
123 APR_RING_INSERT_TAIL((b), ap__b, h2_task_queue, link);  \
124 } while (0)
125
126 /**
127  * Get the next queue in the list
128  * @param e The current queue
129  * @return The next queue
130  */
131 #define H2_TQ_NEXT(e)   APR_RING_NEXT((e), link)
132 /**
133  * Get the previous queue in the list
134  * @param e The current queue
135  * @return The previous queue
136  */
137 #define H2_TQ_PREV(e)   APR_RING_PREV((e), link)
138
139 /**
140  * Remove a queue from its list
141  * @param e The queue to remove
142  */
143 #define H2_TQ_REMOVE(e) APR_RING_REMOVE((e), link)
144
145
146 #define H2_TQ_EMPTY(e)  H2_TASK_LIST_EMPTY(&(e)->tasks)
147
148 #endif /* defined(__mod_h2__h2_task_queue__) */