]> granicus.if.org Git - apache/blob - modules/http2/h2_worker.h
Backport
[apache] / modules / http2 / h2_worker.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_worker__
17 #define __mod_h2__h2_worker__
18
19 struct h2_mplx;
20 struct h2_request;
21 struct h2_task;
22
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.
25  */
26 typedef struct h2_worker h2_worker;
27
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,
32                                             void *ctx,
33                                             struct h2_task **ptask,
34                                             int *psticky);
35
36 /* Invoked just before the worker thread exits. */
37 typedef void h2_worker_done_fn(h2_worker *worker, void *ctx);
38
39
40 struct h2_worker {
41     int id;
42     /** Links to the rest of the workers */
43     APR_RING_ENTRY(h2_worker) link;
44     apr_thread_t *thread;
45     h2_worker_mplx_next_fn *get_next;
46     h2_worker_done_fn *worker_done;
47     void *ctx;
48     int aborted;
49 };
50
51 /**
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
55  */
56 #define H2_WORKER_LIST_SENTINEL(b)      APR_RING_SENTINEL((b), h2_worker, link)
57
58 /**
59  * Determine if the worker list is empty
60  * @param b The list to check
61  * @return true or false
62  */
63 #define H2_WORKER_LIST_EMPTY(b) APR_RING_EMPTY((b), h2_worker, link)
64
65 /**
66  * Return the first worker in a list
67  * @param b The list to query
68  * @return The first worker in the list
69  */
70 #define H2_WORKER_LIST_FIRST(b) APR_RING_FIRST(b)
71
72 /**
73  * Return the last worker in a list
74  * @param b The list to query
75  * @return The last worker int he list
76  */
77 #define H2_WORKER_LIST_LAST(b)  APR_RING_LAST(b)
78
79 /**
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
83  */
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);      \
87     } while (0)
88
89 /**
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
93  */
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);      \
97     } while (0)
98
99 /**
100  * Get the next worker in the list
101  * @param e The current worker
102  * @return The next worker
103  */
104 #define H2_WORKER_NEXT(e)       APR_RING_NEXT((e), link)
105 /**
106  * Get the previous worker in the list
107  * @param e The current worker
108  * @return The previous worker
109  */
110 #define H2_WORKER_PREV(e)       APR_RING_PREV((e), link)
111
112 /**
113  * Remove a worker from its list
114  * @param e The worker to remove
115  */
116 #define H2_WORKER_REMOVE(e)     APR_RING_REMOVE((e), link)
117
118
119 /* Create a new worker with given id, pool and attributes, callbacks
120  * callback parameter.
121  */
122 h2_worker *h2_worker_create(int id,
123                             apr_pool_t *pool,
124                             apr_threadattr_t *attr,
125                             h2_worker_mplx_next_fn *get_next,
126                             h2_worker_done_fn *worker_done,
127                             void *ctx);
128
129 apr_status_t h2_worker_destroy(h2_worker *worker);
130
131 void h2_worker_abort(h2_worker *worker);
132
133 int h2_worker_is_aborted(h2_worker *worker);
134
135 #endif /* defined(__mod_h2__h2_worker__) */