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.
18 #include <apr_thread_cond.h>
20 #include <mpm_common.h>
22 #include <http_core.h>
26 #include "h2_private.h"
32 #include "h2_worker.h"
34 static void* APR_THREAD_FUNC execute(apr_thread_t *thread, void *wctx)
36 h2_worker *worker = (h2_worker *)wctx;
39 while (!worker->aborted) {
42 /* Get a h2_task from the main workers queue. */
43 worker->get_next(worker, worker->ctx, &task, &sticky);
46 h2_task_do(task, thread, worker->id);
47 /* report the task done and maybe get another one from the same
48 * mplx (= master connection), if we can be sticky.
50 if (sticky && !worker->aborted) {
51 h2_mplx_task_done(task->mplx, task, &task);
54 h2_mplx_task_done(task->mplx, task, NULL);
60 worker->worker_done(worker, worker->ctx);
64 h2_worker *h2_worker_create(int id,
66 apr_threadattr_t *attr,
67 h2_worker_mplx_next_fn *get_next,
68 h2_worker_done_fn *worker_done,
71 h2_worker *w = apr_pcalloc(pool, sizeof(h2_worker));
74 APR_RING_ELEM_INIT(w, link);
75 w->get_next = get_next;
76 w->worker_done = worker_done;
78 apr_thread_create(&w->thread, attr, execute, w, pool);
83 apr_status_t h2_worker_destroy(h2_worker *worker)
87 apr_thread_join(&status, worker->thread);
88 worker->thread = NULL;
93 void h2_worker_abort(h2_worker *worker)
98 int h2_worker_is_aborted(h2_worker *worker)
100 return worker->aborted;