]> granicus.if.org Git - apache/blob - modules/http2/h2_workers.h
update of mod_http2 with current trunk version
[apache] / modules / http2 / h2_workers.h
1 /* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
2  
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __mod_h2__h2_workers__
18 #define __mod_h2__h2_workers__
19
20 /* Thread pool specific to executing h2_tasks. Has a minimum and maximum 
21  * number of workers it creates. Starts with minimum workers and adds
22  * some on load, reduces the number again when idle.
23  *
24  */
25 struct apr_thread_mutex_t;
26 struct apr_thread_cond_t;
27 struct h2_mplx;
28 struct h2_task;
29 struct h2_task_queue;
30
31 typedef struct h2_workers h2_workers;
32
33 struct h2_workers {
34     server_rec *s;
35     apr_pool_t *pool;
36     int aborted;
37     
38     int next_worker_id;
39     int min_size;
40     int max_size;
41     
42     apr_threadattr_t *thread_attr;
43     
44     APR_RING_HEAD(h2_worker_list, h2_worker) workers;
45     APR_RING_HEAD(h2_worker_zombies, h2_worker) zombies;
46     APR_RING_HEAD(h2_mplx_list, h2_mplx) mplxs;
47     
48     int worker_count;
49     volatile apr_uint32_t max_idle_secs;
50     volatile apr_uint32_t idle_worker_count;
51     
52     struct apr_thread_mutex_t *lock;
53     struct apr_thread_cond_t *mplx_added;
54 };
55
56
57 /* Create a worker pool with the given minimum and maximum number of
58  * threads.
59  */
60 h2_workers *h2_workers_create(server_rec *s, apr_pool_t *pool,
61                               int min_size, int max_size);
62
63 /* Destroy the worker pool and all its threads. 
64  */
65 void h2_workers_destroy(h2_workers *workers);
66
67 /**
68  * Registers a h2_mplx for task scheduling. If this h2_mplx runs
69  * out of tasks, it will be automatically be unregistered. Should
70  * new tasks arrive, it needs to be registered again.
71  */
72 apr_status_t h2_workers_register(h2_workers *workers, 
73                                  struct h2_mplx *m);
74
75 /**
76  * Remove a h2_mplx from the worker registry.
77  */
78 apr_status_t h2_workers_unregister(h2_workers *workers, 
79                                    struct h2_mplx *m);
80
81 /**
82  * Set the amount of seconds a h2_worker should wait for new tasks
83  * before shutting down (if there are more than the minimum number of
84  * workers).
85  */
86 void h2_workers_set_max_idle_secs(h2_workers *workers, int idle_secs);
87
88 #endif /* defined(__mod_h2__h2_workers__) */