1 /* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __mod_h2__h2_workers__
18 #define __mod_h2__h2_workers__
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.
25 struct apr_thread_mutex_t;
26 struct apr_thread_cond_t;
31 typedef struct h2_workers h2_workers;
44 apr_size_t max_tx_handles;
45 apr_size_t spare_tx_handles;
47 unsigned int aborted : 1;
49 apr_threadattr_t *thread_attr;
51 APR_RING_HEAD(h2_worker_list, h2_worker) workers;
52 APR_RING_HEAD(h2_worker_zombies, h2_worker) zombies;
53 APR_RING_HEAD(h2_mplx_list, h2_mplx) mplxs;
56 struct apr_thread_mutex_t *lock;
57 struct apr_thread_cond_t *mplx_added;
59 struct apr_thread_mutex_t *tx_lock;
63 /* Create a worker pool with the given minimum and maximum number of
66 h2_workers *h2_workers_create(server_rec *s, apr_pool_t *pool,
67 int min_size, int max_size,
68 apr_size_t max_tx_handles);
70 /* Destroy the worker pool and all its threads.
72 void h2_workers_destroy(h2_workers *workers);
75 * Registers a h2_mplx for task scheduling. If this h2_mplx runs
76 * out of tasks, it will be automatically be unregistered. Should
77 * new tasks arrive, it needs to be registered again.
79 apr_status_t h2_workers_register(h2_workers *workers, struct h2_mplx *m);
82 * Remove a h2_mplx from the worker registry.
84 apr_status_t h2_workers_unregister(h2_workers *workers, struct h2_mplx *m);
87 * Set the amount of seconds a h2_worker should wait for new tasks
88 * before shutting down (if there are more than the minimum number of
91 void h2_workers_set_max_idle_secs(h2_workers *workers, int idle_secs);
94 * Reservation of file handles available for transfer between workers
95 * and master connections.
97 * When handling output from request processing, file handles are often
98 * encountered when static files are served. The most efficient way is then
99 * to forward the handle itself to the master connection where it can be
100 * read or sendfile'd to the client. But file handles are a scarce resource,
101 * so there needs to be a limit on how many handles are transferred this way.
103 * h2_workers keeps track of the number of reserved handles and observes a
104 * configurable maximum value.
106 * @param workers the workers instance
107 * @param count how many handles the caller wishes to reserve
108 * @return the number of reserved handles, may be 0.
110 apr_size_t h2_workers_tx_reserve(h2_workers *workers, apr_size_t count);
113 * Return a number of reserved file handles back to the pool. The number
114 * overall may not exceed the numbers reserved.
115 * @param workers the workers instance
116 * @param count how many handles are returned to the pool
118 void h2_workers_tx_free(h2_workers *workers, apr_size_t count);
120 #endif /* defined(__mod_h2__h2_workers__) */