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_worker__
17 #define __mod_h2__h2_worker__
23 /* h2_worker is a basically a apr_thread_t that reads fromt he h2_workers
24 * task queue and runs h2_tasks it is given.
26 typedef struct h2_worker h2_worker;
28 /* Invoked when the worker wants a new task to process. Will block
29 * until a h2_mplx becomes available or the worker itself
30 * gets aborted (idle timeout, for example). */
31 typedef apr_status_t h2_worker_mplx_next_fn(h2_worker *worker,
33 struct h2_task **ptask,
36 /* Invoked just before the worker thread exits. */
37 typedef void h2_worker_done_fn(h2_worker *worker, void *ctx);
42 /** Links to the rest of the workers */
43 APR_RING_ENTRY(h2_worker) link;
45 h2_worker_mplx_next_fn *get_next;
46 h2_worker_done_fn *worker_done;
52 * The magic pointer value that indicates the head of a h2_worker list
53 * @param b The worker list
54 * @return The magic pointer value
56 #define H2_WORKER_LIST_SENTINEL(b) APR_RING_SENTINEL((b), h2_worker, link)
59 * Determine if the worker list is empty
60 * @param b The list to check
61 * @return true or false
63 #define H2_WORKER_LIST_EMPTY(b) APR_RING_EMPTY((b), h2_worker, link)
66 * Return the first worker in a list
67 * @param b The list to query
68 * @return The first worker in the list
70 #define H2_WORKER_LIST_FIRST(b) APR_RING_FIRST(b)
73 * Return the last worker in a list
74 * @param b The list to query
75 * @return The last worker int he list
77 #define H2_WORKER_LIST_LAST(b) APR_RING_LAST(b)
80 * Insert a single worker at the front of a list
81 * @param b The list to add to
82 * @param e The worker to insert
84 #define H2_WORKER_LIST_INSERT_HEAD(b, e) do { \
85 h2_worker *ap__b = (e); \
86 APR_RING_INSERT_HEAD((b), ap__b, h2_worker, link); \
90 * Insert a single worker at the end of a list
91 * @param b The list to add to
92 * @param e The worker to insert
94 #define H2_WORKER_LIST_INSERT_TAIL(b, e) do { \
95 h2_worker *ap__b = (e); \
96 APR_RING_INSERT_TAIL((b), ap__b, h2_worker, link); \
100 * Get the next worker in the list
101 * @param e The current worker
102 * @return The next worker
104 #define H2_WORKER_NEXT(e) APR_RING_NEXT((e), link)
106 * Get the previous worker in the list
107 * @param e The current worker
108 * @return The previous worker
110 #define H2_WORKER_PREV(e) APR_RING_PREV((e), link)
113 * Remove a worker from its list
114 * @param e The worker to remove
116 #define H2_WORKER_REMOVE(e) APR_RING_REMOVE((e), link)
119 /* Create a new worker with given id, pool and attributes, callbacks
120 * callback parameter.
122 h2_worker *h2_worker_create(int id,
124 apr_threadattr_t *attr,
125 h2_worker_mplx_next_fn *get_next,
126 h2_worker_done_fn *worker_done,
129 apr_status_t h2_worker_destroy(h2_worker *worker);
131 void h2_worker_abort(h2_worker *worker);
133 int h2_worker_is_aborted(h2_worker *worker);
135 #endif /* defined(__mod_h2__h2_worker__) */