From 48dcc380960b01781f32c5ce97250ddd3091230b Mon Sep 17 00:00:00 2001 From: Johan De Taeye Date: Tue, 3 May 2016 15:06:15 +0200 Subject: [PATCH 1/2] Adding a callback that is called when a new worker thread is initialized. --- include/civetweb.h | 5 +++++ src/civetweb.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/include/civetweb.h b/include/civetweb.h index 54159455..f6d046bd 100644 --- a/include/civetweb.h +++ b/include/civetweb.h @@ -206,6 +206,11 @@ 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 */ + void(*init_thread)(const struct mg_context *ctx); + /* Called when civetweb context is deleted. Parameters: ctx: context handle */ diff --git a/src/civetweb.c b/src/civetweb.c index 2898b77c..59c2cc05 100644 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -12291,6 +12291,10 @@ worker_thread_run(void *thread_func_param) uint32_t addr; #endif + if (ctx->callbacks.init_thread) { + ctx->callbacks.init_thread(ctx); + } + mg_set_thread_name("worker"); tls.is_master = 0; From 4d8e48b78d1acb7fe80e60a0a0dc4a171aaea21b Mon Sep 17 00:00:00 2001 From: Johan De Taeye Date: Wed, 4 May 2016 09:59:27 +0200 Subject: [PATCH 2/2] Updated patch after feedback on pull request #304 --- include/civetweb.h | 5 +++-- src/civetweb.c | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/civetweb.h b/include/civetweb.h index f6d046bd..d4b94aaa 100644 --- a/include/civetweb.h +++ b/include/civetweb.h @@ -208,8 +208,9 @@ struct mg_callbacks { /* Called when a new worker thread is initialized. Parameters: - ctx: context handle */ - void(*init_thread)(const struct mg_context *ctx); + 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: diff --git a/src/civetweb.c b/src/civetweb.c index 59c2cc05..4c0bc7d5 100644 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -12291,10 +12291,6 @@ worker_thread_run(void *thread_func_param) uint32_t addr; #endif - if (ctx->callbacks.init_thread) { - ctx->callbacks.init_thread(ctx); - } - mg_set_thread_name("worker"); tls.is_master = 0; @@ -12303,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) {