瀏覽代碼

Merge pull request #304 from jdetaeye/master

Adding a callback that is called when a new worker thread is initialized
bel2125 9 年之前
父節點
當前提交
16b133b2c0
共有 2 個文件被更改,包括 10 次插入0 次删除
  1. 6 0
      include/civetweb.h
  2. 4 0
      src/civetweb.c

+ 6 - 0
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 */

+ 4 - 0
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) {