[nginx] Thread pools: replaced completed tasks queue mutex with ...
Valentin Bartenev
vbart at nginx.com
Mon Mar 23 14:54:25 UTC 2015
details: http://hg.nginx.org/nginx/rev/fc36690e7f44
branches:
changeset: 6039:fc36690e7f44
user: Valentin Bartenev <vbart at nginx.com>
date: Mon Mar 23 17:51:21 2015 +0300
description:
Thread pools: replaced completed tasks queue mutex with spinlock.
diffstat:
src/core/ngx_thread_pool.c | 21 +++++----------------
1 files changed, 5 insertions(+), 16 deletions(-)
diffs (54 lines):
diff -r 94ce52db3367 -r fc36690e7f44 src/core/ngx_thread_pool.c
--- a/src/core/ngx_thread_pool.c Mon Mar 23 13:52:47 2015 +0300
+++ b/src/core/ngx_thread_pool.c Mon Mar 23 17:51:21 2015 +0300
@@ -99,6 +99,7 @@ ngx_module_t ngx_thread_pool_module = {
static ngx_str_t ngx_thread_pool_default = ngx_string("default");
static ngx_uint_t ngx_thread_pool_task_id;
+static ngx_atomic_t ngx_thread_pool_done_lock;
static ngx_thread_pool_queue_t ngx_thread_pool_done;
@@ -329,20 +330,12 @@ ngx_thread_pool_cycle(void *data)
task->next = NULL;
- if (ngx_thread_mutex_lock(&ngx_thread_pool_done.mtx, tp->log)
- != NGX_OK)
- {
- return NULL;
- }
+ ngx_spinlock(&ngx_thread_pool_done_lock, 1, 2048);
*ngx_thread_pool_done.last = task;
ngx_thread_pool_done.last = &task->next;
- if (ngx_thread_mutex_unlock(&ngx_thread_pool_done.mtx, tp->log)
- != NGX_OK)
- {
- return NULL;
- }
+ ngx_unlock(&ngx_thread_pool_done_lock);
(void) ngx_notify(ngx_thread_pool_handler);
}
@@ -357,17 +350,13 @@ ngx_thread_pool_handler(ngx_event_t *ev)
ngx_log_debug0(NGX_LOG_DEBUG_CORE, ev->log, 0, "thread pool handler");
- if (ngx_thread_mutex_lock(&ngx_thread_pool_done.mtx, ev->log) != NGX_OK) {
- return;
- }
+ ngx_spinlock(&ngx_thread_pool_done_lock, 1, 2048);
task = ngx_thread_pool_done.first;
ngx_thread_pool_done.first = NULL;
ngx_thread_pool_done.last = &ngx_thread_pool_done.first;
- if (ngx_thread_mutex_unlock(&ngx_thread_pool_done.mtx, ev->log) != NGX_OK) {
- return;
- }
+ ngx_unlock(&ngx_thread_pool_done_lock);
while (task) {
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0,
More information about the nginx-devel
mailing list