Welcome! Log In Create A New Profile

Advanced

[nginx] Thread pools: keep waiting tasks counter in ngx_thread_p...

Ruslan Ermilov
March 19, 2015 04:24PM
details: http://hg.nginx.org/nginx/rev/32099b107191
branches:
changeset: 6025:32099b107191
user: Ruslan Ermilov <ru@nginx.com>
date: Thu Mar 19 23:19:35 2015 +0300
description:
Thread pools: keep waiting tasks counter in ngx_thread_pool_t.

It's not needed for completed tasks queue.

No functional changes.

diffstat:

src/core/ngx_thread_pool.c | 16 +++++++---------
1 files changed, 7 insertions(+), 9 deletions(-)

diffs (73 lines):

diff -r 199c0dd313ea -r 32099b107191 src/core/ngx_thread_pool.c
--- a/src/core/ngx_thread_pool.c Sun Mar 15 21:46:21 2015 +0800
+++ b/src/core/ngx_thread_pool.c Thu Mar 19 23:19:35 2015 +0300
@@ -18,17 +18,16 @@ typedef struct {

typedef struct {
ngx_thread_mutex_t mtx;
- ngx_uint_t count;
ngx_thread_task_t *first;
ngx_thread_task_t **last;
} ngx_thread_pool_queue_t;


struct ngx_thread_pool_s {
+ ngx_thread_pool_queue_t queue;
+ ngx_uint_t waiting;
ngx_thread_cond_t cond;

- ngx_thread_pool_queue_t queue;
-
ngx_log_t *log;
ngx_pool_t *pool;

@@ -163,7 +162,6 @@ ngx_thread_pool_init(ngx_thread_pool_t *
static ngx_int_t
ngx_thread_pool_queue_init(ngx_thread_pool_queue_t *queue, ngx_log_t *log)
{
- queue->count = 0;
queue->first = NULL;
queue->last = &queue->first;

@@ -217,12 +215,12 @@ ngx_thread_task_post(ngx_thread_pool_t *
return NGX_ERROR;
}

- if (tp->queue.count >= tp->max_queue) {
+ if (tp->waiting >= tp->max_queue) {
(void) ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log);

ngx_log_error(NGX_LOG_ERR, tp->log, 0,
"thread pool \"%V\" queue overflow: %ui tasks waiting",
- &tp->name, tp->queue.count);
+ &tp->name, tp->waiting);
return NGX_ERROR;
}

@@ -239,7 +237,7 @@ ngx_thread_task_post(ngx_thread_pool_t *
*tp->queue.last = task;
tp->queue.last = &task->next;

- tp->queue.count++;
+ tp->waiting++;

(void) ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log);

@@ -285,7 +283,7 @@ ngx_thread_pool_cycle(void *data)
return NULL;
}

- while (tp->queue.count == 0) {
+ while (tp->waiting == 0) {
if (ngx_thread_cond_wait(&tp->cond, &tp->queue.mtx, tp->log)
!= NGX_OK)
{
@@ -294,7 +292,7 @@ ngx_thread_pool_cycle(void *data)
}
}

- tp->queue.count--;
+ tp->waiting--;

task = tp->queue.first;
tp->queue.first = task->next;

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

[nginx] Thread pools: keep waiting tasks counter in ngx_thread_p...

Ruslan Ermilov 425 March 19, 2015 04:24PM



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

Online Users

Guests: 201
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready