Welcome! Log In Create A New Profile

Advanced

[nginx] Thread pools: implemented graceful exiting of threads.

Valentin Bartenev
March 23, 2015 10:56AM
details: http://hg.nginx.org/nginx/rev/abde398f34a7
branches:
changeset: 6042:abde398f34a7
user: Valentin Bartenev <vbart@nginx.com>
date: Mon Mar 23 17:51:21 2015 +0300
description:
Thread pools: implemented graceful exiting of threads.

diffstat:

src/core/ngx_thread_pool.c | 37 ++++++++++++++++++++++++++++++++++---
1 files changed, 34 insertions(+), 3 deletions(-)

diffs (58 lines):

diff -r 2097cd49a158 -r abde398f34a7 src/core/ngx_thread_pool.c
--- a/src/core/ngx_thread_pool.c Mon Mar 23 17:51:21 2015 +0300
+++ b/src/core/ngx_thread_pool.c Mon Mar 23 17:51:21 2015 +0300
@@ -46,6 +46,7 @@ struct ngx_thread_pool_s {
static ngx_int_t ngx_thread_pool_init(ngx_thread_pool_t *tp, ngx_log_t *log,
ngx_pool_t *pool);
static void ngx_thread_pool_destroy(ngx_thread_pool_t *tp);
+static void ngx_thread_pool_exit_handler(void *data, ngx_log_t *log);

static void *ngx_thread_pool_cycle(void *data);
static void ngx_thread_pool_handler(ngx_event_t *ev);
@@ -163,13 +164,43 @@ ngx_thread_pool_init(ngx_thread_pool_t *
static void
ngx_thread_pool_destroy(ngx_thread_pool_t *tp)
{
- /* TODO: exit threads */
+ ngx_uint_t n;
+ ngx_thread_task_t task;
+ volatile ngx_uint_t lock;

-#if 0
+ ngx_memzero(&task, sizeof(ngx_thread_task_t));
+
+ task.handler = ngx_thread_pool_exit_handler;
+ task.ctx = (void *) &lock;
+
+ for (n = 0; n < tp->threads; n++) {
+ lock = 1;
+
+ if (ngx_thread_task_post(tp, &task) != NGX_OK) {
+ return;
+ }
+
+ while (lock) {
+ ngx_sched_yield();
+ }
+
+ task.event.active = 0;
+ }
+
(void) ngx_thread_cond_destroy(&tp->cond, tp->log);

(void) ngx_thread_mutex_destroy(&tp->mtx, tp->log);
- #endif
+}
+
+
+static void
+ngx_thread_pool_exit_handler(void *data, ngx_log_t *log)
+{
+ ngx_uint_t *lock = data;
+
+ *lock = 0;
+
+ pthread_exit(0);
}



_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Thread pools: implemented graceful exiting of threads.

Valentin Bartenev 522 March 23, 2015 10:56AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 176
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready