1 /* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __mod_h2__h2_task_queue__
17 #define __mod_h2__h2_task_queue__
22 * A simple ring of rings that keeps a list of h2_tasks and can
23 * be ringed itself, using the APR RING macros.
25 typedef struct h2_task_queue h2_task_queue;
27 struct h2_task_queue {
28 APR_RING_ENTRY(h2_task_queue) link;
29 APR_RING_HEAD(h2_tasks, h2_task) tasks;
34 * Allocate a new queue from the pool and initialize.
35 * @param id the identifier of the queue
36 * @param pool the memory pool
38 h2_task_queue *h2_tq_create(long id, apr_pool_t *pool);
41 * Release all queue tasks.
42 * @param q the queue to destroy
44 void h2_tq_destroy(h2_task_queue *q);
47 * Return != 0 iff there are no tasks in the queue.
48 * @param q the queue to check
50 int h2_tq_empty(h2_task_queue *q);
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
57 void h2_tq_append(h2_task_queue *q, struct h2_task *task);
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
65 apr_status_t h2_tq_remove(h2_task_queue *q, struct h2_task *task);
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
72 h2_task *h2_tq_pop_first(h2_task_queue *q);
74 /*******************************************************************************
76 ******************************************************************************/
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
83 #define H2_TQ_LIST_SENTINEL(b) APR_RING_SENTINEL((b), h2_task_queue, link)
86 * Determine if the queue list is empty
87 * @param b The list to check
88 * @return true or false
90 #define H2_TQ_LIST_EMPTY(b) APR_RING_EMPTY((b), h2_task_queue, link)
93 * Return the first queue in a list
94 * @param b The list to query
95 * @return The first queue in the list
97 #define H2_TQ_LIST_FIRST(b) APR_RING_FIRST(b)
100 * Return the last queue in a list
101 * @param b The list to query
102 * @return The last queue int he list
104 #define H2_TQ_LIST_LAST(b) APR_RING_LAST(b)
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
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); \
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
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); \
127 * Get the next queue in the list
128 * @param e The current queue
129 * @return The next queue
131 #define H2_TQ_NEXT(e) APR_RING_NEXT((e), link)
133 * Get the previous queue in the list
134 * @param e The current queue
135 * @return The previous queue
137 #define H2_TQ_PREV(e) APR_RING_PREV((e), link)
140 * Remove a queue from its list
141 * @param e The queue to remove
143 #define H2_TQ_REMOVE(e) APR_RING_REMOVE((e), link)
146 #define H2_TQ_EMPTY(e) H2_TASK_LIST_EMPTY(&(e)->tasks)
148 #endif /* defined(__mod_h2__h2_task_queue__) */