diff --git a/include/civetweb.h b/include/civetweb.h index 54159455..d4b94aaa 100644 --- a/include/civetweb.h +++ b/include/civetweb.h @@ -206,6 +206,12 @@ struct mg_callbacks { ctx: context handle */ void (*init_context)(const struct mg_context *ctx); + /* Called when a new worker thread is initialized. + Parameters: + ctx: context handle + thread_type: a value of 1 indicates a worker thread. */ + void(*init_thread)(const struct mg_context *ctx, int thread_type); + /* Called when civetweb context is deleted. Parameters: ctx: context handle */ diff --git a/src/civetweb.c b/src/civetweb.c index 2898b77c..4c0bc7d5 100644 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -12299,6 +12299,10 @@ worker_thread_run(void *thread_func_param) tls.pthread_cond_helper_mutex = CreateEvent(NULL, FALSE, FALSE, NULL); #endif + if (ctx->callbacks.init_thread) { + ctx->callbacks.init_thread(ctx, 1); + } + conn = (struct mg_connection *)mg_calloc(1, sizeof(*conn) + MAX_REQUEST_SIZE); if (conn == NULL) {