summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/nxt_application.c119
-rw-r--r--src/nxt_buf.c10
-rw-r--r--src/nxt_buf_filter.c95
-rw-r--r--src/nxt_buf_filter.h9
-rw-r--r--src/nxt_chan.c82
-rw-r--r--src/nxt_chan.h12
-rw-r--r--src/nxt_cycle.c141
-rw-r--r--src/nxt_cycle.h11
-rw-r--r--src/nxt_epoll.c129
-rw-r--r--src/nxt_event_conn.c75
-rw-r--r--src/nxt_event_conn.h108
-rw-r--r--src/nxt_event_conn_accept.c133
-rw-r--r--src/nxt_event_conn_connect.c71
-rw-r--r--src/nxt_event_conn_job_sendfile.c69
-rw-r--r--src/nxt_event_conn_proxy.c257
-rw-r--r--src/nxt_event_conn_read.c48
-rw-r--r--src/nxt_event_conn_write.c78
-rw-r--r--src/nxt_event_engine.c120
-rw-r--r--src/nxt_event_engine.h7
-rw-r--r--src/nxt_event_fd.h2
-rw-r--r--src/nxt_event_file.h1
-rw-r--r--src/nxt_event_set.h2
-rw-r--r--src/nxt_event_timer.c6
-rw-r--r--src/nxt_event_timer.h5
-rw-r--r--src/nxt_fastcgi_record_parse.c10
-rw-r--r--src/nxt_fastcgi_source.c124
-rw-r--r--src/nxt_fastcgi_source.h6
-rw-r--r--src/nxt_fiber.c197
-rw-r--r--src/nxt_fiber.h11
-rw-r--r--src/nxt_freebsd_sendfile.c4
-rw-r--r--src/nxt_http_chunk_parse.c10
-rw-r--r--src/nxt_http_parse.h4
-rw-r--r--src/nxt_http_source.c140
-rw-r--r--src/nxt_http_source.h4
-rw-r--r--src/nxt_job.c49
-rw-r--r--src/nxt_job.h6
-rw-r--r--src/nxt_job_file.c15
-rw-r--r--src/nxt_job_file.h2
-rw-r--r--src/nxt_job_resolve.c2
-rw-r--r--src/nxt_kqueue.c134
-rw-r--r--src/nxt_lib.c6
-rw-r--r--src/nxt_linux_sendfile.c2
-rw-r--r--src/nxt_log.c2
-rw-r--r--src/nxt_log.h34
-rw-r--r--src/nxt_log_moderation.c6
-rw-r--r--src/nxt_macosx_sendfile.c4
-rw-r--r--src/nxt_main.c2
-rw-r--r--src/nxt_main.h2
-rw-r--r--src/nxt_master_process.c149
-rw-r--r--src/nxt_master_process.h5
-rw-r--r--src/nxt_openssl.c94
-rw-r--r--src/nxt_poll.c44
-rw-r--r--src/nxt_process_chan.c62
-rw-r--r--src/nxt_process_chan.h26
-rw-r--r--src/nxt_select.c36
-rw-r--r--src/nxt_sendbuf.c14
-rw-r--r--src/nxt_sendbuf.h5
-rw-r--r--src/nxt_sockaddr.c2
-rw-r--r--src/nxt_socketpair.c29
-rw-r--r--src/nxt_source.h8
-rw-r--r--src/nxt_ssltls.h2
-rw-r--r--src/nxt_stream_source.c130
-rw-r--r--src/nxt_stream_source.h5
-rw-r--r--src/nxt_thread.c5
-rw-r--r--src/nxt_thread_pool.c54
-rw-r--r--src/nxt_thread_pool.h4
-rw-r--r--src/nxt_unix.h2
-rw-r--r--src/nxt_work_queue.c51
-rw-r--r--src/nxt_work_queue.h44
-rw-r--r--src/nxt_worker_process.c51
70 files changed, 1688 insertions, 1500 deletions
diff --git a/src/nxt_application.c b/src/nxt_application.c
index 08d32b37..0d618744 100644
--- a/src/nxt_application.c
+++ b/src/nxt_application.c
@@ -19,17 +19,17 @@ static nxt_app_request_t *nxt_app_request_create(nxt_socket_t s,
static void nxt_app_conn_update(nxt_thread_t *thr, nxt_event_conn_t *c,
nxt_log_t *log);
static nxt_int_t nxt_app_write_finish(nxt_app_request_t *r);
-static void nxt_app_buf_complettion(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_app_delivery_handler(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_app_delivery_ready(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_app_delivery_complettion(nxt_thread_t *thr, void *obj,
+static void nxt_app_buf_completion(nxt_task_t *task, void *obj, void *data);
+static void nxt_app_delivery_handler(nxt_task_t *task, void *obj, void *data);
+static void nxt_app_delivery_ready(nxt_task_t *task, void *obj, void *data);
+static void nxt_app_delivery_completion(nxt_task_t *task, void *obj,
void *data);
-static void nxt_app_delivery_error(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_app_delivery_timeout(nxt_thread_t *thr, void *obj, void *data);
+static void nxt_app_delivery_error(nxt_task_t *task, void *obj, void *data);
+static void nxt_app_delivery_timeout(nxt_task_t *task, void *obj, void *data);
static nxt_msec_t nxt_app_delivery_timer_value(nxt_event_conn_t *c,
uintptr_t data);
-static void nxt_app_delivery_done(nxt_thread_t *thr, nxt_event_conn_t *c);
-static void nxt_app_close_request(nxt_thread_t *thr, nxt_app_request_t *r);
+static void nxt_app_delivery_done(nxt_task_t *task, nxt_event_conn_t *c);
+static void nxt_app_close_request(nxt_task_t *task, nxt_app_request_t *r);
typedef struct nxt_app_http_parse_state_s nxt_app_http_parse_state_t;
@@ -229,6 +229,13 @@ nxt_app_request_create(nxt_socket_t s, nxt_log_t *log)
c->socket.fd = s;
c->socket.data = r;
+ c->task.thread = nxt_thread();
+ c->task.log = log;
+ c->task.ident = log->ident;
+ c->socket.task = &c->task;
+ c->read_timer.task = &c->task;
+ c->write_timer.task = &c->task;
+
r->mem_pool = mp;
r->event_conn = c;
r->log = log;
@@ -480,8 +487,6 @@ nxt_app_http_process_headers(nxt_app_request_t *r)
static void
nxt_app_conn_update(nxt_thread_t *thr, nxt_event_conn_t *c, nxt_log_t *log)
{
- static nxt_atomic_t ident = 1;
-
c->socket.write_ready = 1;
c->socket.log = &c->log;
@@ -490,11 +495,15 @@ nxt_app_conn_update(nxt_thread_t *thr, nxt_event_conn_t *c, nxt_log_t *log)
/* The while loop skips possible uint32_t overflow. */
while (c->log.ident == 0) {
- c->log.ident = (uint32_t) nxt_atomic_fetch_add(&ident, 1);
+ c->log.ident = nxt_task_next_ident();
}
thr->engine->connections++;
+ c->task.thread = thr;
+ c->task.log = &c->log;
+ c->task.ident = c->log.ident;
+
c->io = thr->engine->event->io;
c->max_chunk = NXT_INT32_T_MAX;
c->sendfile = NXT_CONN_SENDFILE_UNSET;
@@ -568,10 +577,11 @@ nxt_app_http_read_body(nxt_app_request_t *r, u_char *data, size_t len)
nxt_int_t
nxt_app_write(nxt_app_request_t *r, const u_char *data, size_t len)
{
- size_t free;
- nxt_err_t err;
- nxt_buf_t *b, *out, **next;
- nxt_uint_t bufs;
+ size_t free;
+ nxt_err_t err;
+ nxt_buf_t *b, *out, **next;
+ nxt_uint_t bufs;
+ nxt_event_conn_t *c;
out = NULL;
next = &out;
@@ -609,9 +619,10 @@ nxt_app_write(nxt_app_request_t *r, const u_char *data, size_t len)
if (bufs == nxt_app_buf_max_number) {
bufs = 0;
*next = NULL;
+ c = r->event_conn;
nxt_event_engine_post(nxt_app_engine, nxt_app_delivery_handler,
- r->event_conn, out, &nxt_main_log);
+ &c->task, c, out, &nxt_main_log);
out = NULL;
next = &out;
@@ -652,7 +663,7 @@ nxt_app_write(nxt_app_request_t *r, const u_char *data, size_t len)
return NXT_ERROR;
}
- b->completion_handler = nxt_app_buf_complettion;
+ b->completion_handler = nxt_app_buf_completion;
nxt_app_buf_current_number++;
}
@@ -664,9 +675,10 @@ nxt_app_write(nxt_app_request_t *r, const u_char *data, size_t len)
if (out != NULL) {
*next = NULL;
+ c = r->event_conn;
nxt_event_engine_post(nxt_app_engine, nxt_app_delivery_handler,
- r->event_conn, out, &nxt_main_log);
+ &c->task, c, out, &nxt_main_log);
}
return NXT_OK;
@@ -676,14 +688,15 @@ nxt_app_write(nxt_app_request_t *r, const u_char *data, size_t len)
static nxt_int_t
nxt_app_write_finish(nxt_app_request_t *r)
{
- nxt_buf_t *b, *out;
+ nxt_buf_t *b, *out;
+ nxt_event_conn_t *c;
b = nxt_buf_sync_alloc(r->mem_pool, NXT_BUF_SYNC_LAST);
if (nxt_slow_path(b == NULL)) {
return NXT_ERROR;
}
- b->completion_handler = nxt_app_buf_complettion;
+ b->completion_handler = nxt_app_buf_completion;
b->parent = (nxt_buf_t *) r;
out = r->output_buf;
@@ -696,21 +709,23 @@ nxt_app_write_finish(nxt_app_request_t *r)
out = b;
}
+ c = r->event_conn;
+
nxt_event_engine_post(nxt_app_engine, nxt_app_delivery_handler,
- r->event_conn, out, &nxt_main_log);
+ &c->task, c, out, &nxt_main_log);
return NXT_OK;
}
static void
-nxt_app_buf_complettion(nxt_thread_t *thr, void *obj, void *data)
+nxt_app_buf_completion(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b;
b = obj;
- nxt_log_debug(thr->log, "app buf completion");
+ nxt_debug(task, "app buf completion");
b->next = nxt_app_buf_done;
nxt_app_buf_done = b;
@@ -718,7 +733,7 @@ nxt_app_buf_complettion(nxt_thread_t *thr, void *obj, void *data)
static void
-nxt_app_delivery_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_app_delivery_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b;
nxt_mem_pool_t *mp;
@@ -727,7 +742,7 @@ nxt_app_delivery_handler(nxt_thread_t *thr, void *obj, void *data)
c = obj;
b = data;
- nxt_log_debug(thr->log, "app delivery handler");
+ nxt_debug(task, "app delivery handler");
if (c->write != NULL) {
nxt_buf_chain_add(&c->write, b);
@@ -742,21 +757,20 @@ nxt_app_delivery_handler(nxt_thread_t *thr, void *obj, void *data)
}
c->mem_pool = mp;
- nxt_app_conn_update(thr, c, &nxt_main_log);
+ nxt_app_conn_update(task->thread, c, &nxt_main_log);
}
if (c->socket.timedout || c->socket.error != 0) {
nxt_buf_chain_add(&nxt_app_buf_done, b);
- nxt_thread_work_queue_add(thr, c->write_work_queue,
- nxt_app_delivery_complettion, c, NULL,
- thr->log);
+ nxt_thread_work_queue_add(task->thread, c->write_work_queue,
+ nxt_app_delivery_completion, task, c, NULL);
return;
}
c->write = b;
c->write_state = &nxt_app_delivery_write_state;
- nxt_event_conn_write(thr, c);
+ nxt_event_conn_write(task, c);
}
@@ -777,24 +791,29 @@ static const nxt_event_conn_state_t nxt_app_delivery_write_state
static void
-nxt_app_delivery_ready(nxt_thread_t *thr, void *obj, void *data)
+nxt_app_delivery_ready(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
c = obj;
- nxt_thread_work_queue_add(thr, c->write_work_queue,
- nxt_app_delivery_complettion, c, NULL, thr->log);
+ nxt_debug(task, "app delivery ready");
+
+ nxt_thread_work_queue_add(task->thread, c->write_work_queue,
+ nxt_app_delivery_completion, task, c, NULL);
}
static void
-nxt_app_delivery_complettion(nxt_thread_t *thr, void *obj, void *data)
+nxt_app_delivery_completion(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b, *bn, *free;
+ nxt_thread_t *thread;
nxt_app_request_t *r;
- nxt_log_debug(thr->log, "app delivery complettion");
+ thread = task->thread;
+
+ nxt_debug(task, "app delivery completion");
free = NULL;
@@ -813,7 +832,7 @@ nxt_app_delivery_complettion(nxt_thread_t *thr, void *obj, void *data)
if (nxt_buf_is_last(b)) {
r = (nxt_app_request_t *) b->parent;
- nxt_app_close_request(thr, r);
+ nxt_app_close_request(task, r);
}
}
@@ -831,35 +850,35 @@ nxt_app_delivery_complettion(nxt_thread_t *thr, void *obj, void *data)
(void) nxt_thread_mutex_unlock(&nxt_app_mutex);
- nxt_thread_time_update(thr);
+ nxt_thread_time_update(thread);
(void) nxt_thread_cond_signal(&nxt_app_cond);
}
static void
-nxt_app_delivery_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_app_delivery_error(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
c = obj;
- nxt_log_debug(thr->log, "app delivery error");
+ nxt_debug(task, "app delivery error");
- nxt_app_delivery_done(thr, c);
+ nxt_app_delivery_done(task, c);
}
static void
-nxt_app_delivery_timeout(nxt_thread_t *thr, void *obj, void *data)
+nxt_app_delivery_timeout(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
c = obj;
- nxt_log_debug(thr->log, "app delivery timeout");
+ nxt_debug(task, "app delivery timeout");
- nxt_app_delivery_done(thr, c);
+ nxt_app_delivery_done(task, c);
}
@@ -872,31 +891,33 @@ nxt_app_delivery_timer_value(nxt_event_conn_t *c, uintptr_t data)
static void
-nxt_app_delivery_done(nxt_thread_t *thr, nxt_event_conn_t *c)
+nxt_app_delivery_done(nxt_task_t *task, nxt_event_conn_t *c)
{
if (c->write == NULL) {
return;
}
+ nxt_debug(task, "app delivery done");
+
nxt_buf_chain_add(&nxt_app_buf_done, c->write);
c->write = NULL;
- nxt_thread_work_queue_add(thr, c->write_work_queue,
- nxt_app_delivery_complettion, c, NULL, thr->log);
+ nxt_thread_work_queue_add(task->thread, c->write_work_queue,
+ nxt_app_delivery_completion, task, c, NULL);
}
static void
-nxt_app_close_request(nxt_thread_t *thr, nxt_app_request_t *r)
+nxt_app_close_request(nxt_task_t *task, nxt_app_request_t *r)
{
nxt_event_conn_t *c;
- nxt_log_debug(thr->log, "app close connection");
+ nxt_debug(task, "app close connection");
c = r->event_conn;
- nxt_event_conn_close(thr, c);
+ nxt_event_conn_close(task, c);
nxt_mem_pool_destroy(c->mem_pool);
nxt_mem_pool_destroy(r->mem_pool);
diff --git a/src/nxt_buf.c b/src/nxt_buf.c
index 4789c0c7..88444a3d 100644
--- a/src/nxt_buf.c
+++ b/src/nxt_buf.c
@@ -7,7 +7,7 @@
#include <nxt_main.h>
-static void nxt_buf_completion(nxt_thread_t *thr, void *obj, void *data);
+static void nxt_buf_completion(nxt_task_t *task, void *obj, void *data);
nxt_buf_t *
@@ -144,7 +144,7 @@ nxt_buf_chain_length(nxt_buf_t *b)
static void
-nxt_buf_completion(nxt_thread_t *thr, void *obj, void *data)
+nxt_buf_completion(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b, *parent;
nxt_mem_pool_t *mp;
@@ -152,20 +152,20 @@ nxt_buf_completion(nxt_thread_t *thr, void *obj, void *data)
b = obj;
parent = data;
- nxt_log_debug(thr->log, "buf completion: %p %p", b, b->mem.start);
+ nxt_debug(task, "buf completion: %p %p", b, b->mem.start);
mp = b->data;
nxt_buf_free(mp, b);
if (parent != NULL) {
- nxt_log_debug(thr->log, "parent retain:%uD", parent->retain);
+ nxt_debug(task, "parent retain:%uD", parent->retain);
parent->retain--;
if (parent->retain == 0) {
parent->mem.pos = parent->mem.free;
- parent->completion_handler(thr, parent, parent->parent);
+ parent->completion_handler(task, parent, parent->parent);
}
}
}
diff --git a/src/nxt_buf_filter.c b/src/nxt_buf_filter.c
index 0f040fc9..fff11f96 100644
--- a/src/nxt_buf_filter.c
+++ b/src/nxt_buf_filter.c
@@ -9,28 +9,28 @@
static nxt_int_t nxt_buf_filter_nobuf(nxt_buf_filter_t *f);
nxt_inline void nxt_buf_filter_next(nxt_buf_filter_t *f);
-static void nxt_buf_filter_file_read_start(nxt_thread_t *thr,
+static void nxt_buf_filter_file_read_start(nxt_task_t *task,
nxt_buf_filter_t *f);
-static void nxt_buf_filter_file_read(nxt_thread_t *thr, nxt_buf_filter_t *f);
-static void nxt_buf_filter_file_job_completion(nxt_thread_t *thr,
- void *obj, void *data);
-static void nxt_buf_filter_buf_completion(nxt_thread_t *thr, void *obj,
+static void nxt_buf_filter_file_read(nxt_task_t *task, nxt_buf_filter_t *f);
+static void nxt_buf_filter_file_job_completion(nxt_task_t *task, void *obj,
void *data);
-static void nxt_buf_filter_file_read_error(nxt_thread_t *thr, void *obj,
+static void nxt_buf_filter_buf_completion(nxt_task_t *task, void *obj,
+ void *data);
+static void nxt_buf_filter_file_read_error(nxt_task_t *task, void *obj,
void *data);
void
-nxt_buf_filter_add(nxt_thread_t *thr, nxt_buf_filter_t *f, nxt_buf_t *b)
+nxt_buf_filter_add(nxt_task_t *task, nxt_buf_filter_t *f, nxt_buf_t *b)
{
nxt_buf_chain_add(&f->input, b);
- nxt_buf_filter(thr, f, NULL);
+ nxt_buf_filter(task, f, NULL);
}
void
-nxt_buf_filter(nxt_thread_t *thr, void *obj, void *data)
+nxt_buf_filter(nxt_task_t *task, void *obj, void *data)
{
nxt_int_t ret;
nxt_buf_t *b;
@@ -38,7 +38,7 @@ nxt_buf_filter(nxt_thread_t *thr, void *obj, void *data)
f = obj;
- nxt_log_debug(thr->log, "buf filter");
+ nxt_debug(task, "buf filter");
if (f->done) {
return;
@@ -59,7 +59,7 @@ nxt_buf_filter(nxt_thread_t *thr, void *obj, void *data)
b = f->current;
- nxt_log_debug(thr->log, "buf filter current: %p", b);
+ nxt_debug(task, "buf filter current: %p", b);
if (b == NULL) {
@@ -69,7 +69,7 @@ nxt_buf_filter(nxt_thread_t *thr, void *obj, void *data)
b = f->input;
- nxt_log_debug(thr->log, "buf filter input: %p", b);
+ nxt_debug(task, "buf filter input: %p", b);
if (b == NULL) {
/*
@@ -93,7 +93,7 @@ nxt_buf_filter(nxt_thread_t *thr, void *obj, void *data)
nxt_buf_filter_next(f);
}
- nxt_buf_filter_file_read_start(thr, f);
+ nxt_buf_filter_file_read_start(task, f);
return;
}
}
@@ -139,9 +139,9 @@ nxt_buf_filter(nxt_thread_t *thr, void *obj, void *data)
*/
if (b != NULL && b->mem.pos == b->mem.free) {
f->current = b->next;
- nxt_thread_work_queue_add(thr, f->work_queue,
+ nxt_thread_work_queue_add(task->thread, f->work_queue,
b->completion_handler,
- b, b->parent, thr->log);
+ task, b, b->parent);
}
continue;
@@ -165,8 +165,8 @@ nobuf:
fail:
- nxt_thread_work_queue_add(thr, f->work_queue, f->run->filter_error,
- f, f->data, thr->log);
+ nxt_thread_work_queue_add(task->thread, f->work_queue, f->run->filter_error,
+ task, f, f->data);
}
@@ -208,20 +208,20 @@ nxt_buf_filter_next(nxt_buf_filter_t *f)
void
-nxt_buf_filter_enqueue(nxt_thread_t *thr, nxt_buf_filter_t *f)
+nxt_buf_filter_enqueue(nxt_task_t *task, nxt_buf_filter_t *f)
{
- nxt_log_debug(thr->log, "buf filter enqueue: %d", f->queued);
+ nxt_debug(task, "buf filter enqueue: %d", f->queued);
if (!f->queued && !f->done) {
f->queued = 1;
- nxt_thread_work_queue_add(thr, f->work_queue, nxt_buf_filter,
- f, NULL, thr->log);
+ nxt_thread_work_queue_add(task->thread, f->work_queue, nxt_buf_filter,
+ task, f, NULL);
}
}
static void
-nxt_buf_filter_file_read_start(nxt_thread_t *thr, nxt_buf_filter_t *f)
+nxt_buf_filter_file_read_start(nxt_task_t *task, nxt_buf_filter_t *f)
{
nxt_job_file_t *jbf;
nxt_buf_filter_file_t *ff;
@@ -229,8 +229,9 @@ nxt_buf_filter_file_read_start(nxt_thread_t *thr, nxt_buf_filter_t *f)
ff = f->run->job_file_create(f);
if (nxt_slow_path(ff == NULL)) {
- nxt_thread_work_queue_add(thr, f->work_queue, f->run->filter_error,
- f, f->data, thr->log);
+ nxt_thread_work_queue_add(task->thread, f->work_queue,
+ f->run->filter_error,
+ task, f, f->data);
return;
}
@@ -246,12 +247,12 @@ nxt_buf_filter_file_read_start(nxt_thread_t *thr, nxt_buf_filter_t *f)
f->reading = 1;
- nxt_buf_filter_file_read(thr, f);
+ nxt_buf_filter_file_read(task, f);
}
static void
-nxt_buf_filter_file_read(nxt_thread_t *thr, nxt_buf_filter_t *f)
+nxt_buf_filter_file_read(nxt_task_t *task, nxt_buf_filter_t *f)
{
nxt_int_t ret;
nxt_off_t size;
@@ -296,7 +297,7 @@ nxt_buf_filter_file_read(nxt_thread_t *thr, nxt_buf_filter_t *f)
f->run->job_file_retain(f);
- nxt_job_file_read(thr, &ff->job_file.job);
+ nxt_job_file_read(task, &ff->job_file.job);
return;
}
@@ -316,8 +317,8 @@ nxt_buf_filter_file_read(nxt_thread_t *thr, nxt_buf_filter_t *f)
}
}
- nxt_thread_work_queue_add(thr, f->work_queue, f->run->filter_error,
- f, f->data, thr->log);
+ nxt_thread_work_queue_add(task->thread, f->work_queue, f->run->filter_error,
+ task, f, f->data);
}
@@ -328,7 +329,7 @@ typedef struct {
static void
-nxt_buf_filter_file_job_completion(nxt_thread_t *thr, void *obj, void *data)
+nxt_buf_filter_file_job_completion(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b;
nxt_bool_t done;
@@ -341,8 +342,8 @@ nxt_buf_filter_file_job_completion(nxt_thread_t *thr, void *obj, void *data)
b = jbf->buffer;
jbf->buffer = NULL;
- nxt_log_debug(thr->log, "buf filter file completion: \"%FN\" %O-%O",
- jbf->file.name, b->file_pos, b->file_end);
+ nxt_debug(task, "buf filter file completion: \"%FN\" %O-%O",
+ jbf->file.name, b->file_pos, b->file_end);
f->run->job_file_release(f);
@@ -370,7 +371,7 @@ nxt_buf_filter_file_job_completion(nxt_thread_t *thr, void *obj, void *data)
nxt_buf_chain_add(&f->current, b);
- nxt_buf_filter(thr, f, NULL);
+ nxt_buf_filter(task, f, NULL);
if (b->mem.pos == b->mem.free) {
/*
@@ -383,20 +384,20 @@ nxt_buf_filter_file_job_completion(nxt_thread_t *thr, void *obj, void *data)
if (!done) {
/* Try to allocate another buffer and read the next file part. */
- nxt_buf_filter_file_read(thr, f);
+ nxt_buf_filter_file_read(task, f);
}
return;
fail:
- nxt_thread_work_queue_add(thr, f->work_queue, f->run->filter_error,
- f, f->data, thr->log);
+ nxt_thread_work_queue_add(task->thread, f->work_queue, f->run->filter_error,
+ task, f, f->data);
}
static void
-nxt_buf_filter_buf_completion(nxt_thread_t *thr, void *obj, void *data)
+nxt_buf_filter_buf_completion(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *fb, *b;
nxt_buf_filter_t *f;
@@ -406,9 +407,8 @@ nxt_buf_filter_buf_completion(nxt_thread_t *thr, void *obj, void *data)
ctx = data;
f = ctx->filter;
- nxt_log_debug(thr->log, "buf filter completion: %p \"%FN\" %O-%O",
- b, f->filter_file->job_file.file.name,
- b->file_pos, b->file_end);
+ nxt_debug(task, "buf filter completion: %p \"%FN\" %O-%O",
+ b, f->filter_file->job_file.file.name, b->file_pos, b->file_end);
/* nxt_http_send_filter() might clear a buffer's file status. */
b->is_file = 1;
@@ -419,7 +419,7 @@ nxt_buf_filter_buf_completion(nxt_thread_t *thr, void *obj, void *data)
nxt_buf_pool_free(&f->filter_file->buffers, b);
if (fb->file_pos < fb->file_end) {
- nxt_buf_filter_file_read(thr, f);
+ nxt_buf_filter_file_read(task, f);
return;
}
@@ -428,21 +428,22 @@ nxt_buf_filter_buf_completion(nxt_thread_t *thr, void *obj, void *data)
nxt_job_destroy(&f->filter_file->job_file.job);
- nxt_thread_work_queue_add(thr, f->work_queue, fb->completion_handler,
- fb, fb->parent, thr->log);
+ nxt_thread_work_queue_add(task->thread, f->work_queue,
+ fb->completion_handler,
+ task, fb, fb->parent);
}
- nxt_buf_filter(thr, f, NULL);
+ nxt_buf_filter(task, f, NULL);
}
static void
-nxt_buf_filter_file_read_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_buf_filter_file_read_error(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_filter_t *f;
f = data;
- nxt_thread_work_queue_add(thr, f->work_queue, f->run->filter_error,
- f, f->data, thr->log);
+ nxt_thread_work_queue_add(task->thread, f->work_queue, f->run->filter_error,
+ task, f, f->data);
}
diff --git a/src/nxt_buf_filter.h b/src/nxt_buf_filter.h
index 8252ca3d..b1015455 100644
--- a/src/nxt_buf_filter.h
+++ b/src/nxt_buf_filter.h
@@ -77,8 +77,7 @@ typedef struct {
nxt_int_t (*filter_sync_last)(nxt_buf_filter_t *f);
void (*filter_next)(nxt_buf_filter_t *f);
- void (*filter_error)(nxt_thread_t *thr, void *obj,
- void *data);
+ nxt_work_handler_t filter_error;
nxt_buf_filter_file_t *(*job_file_create)(nxt_buf_filter_t *f);
void (*job_file_retain)(nxt_buf_filter_t *f);
@@ -107,10 +106,10 @@ struct nxt_buf_filter_s {
};
-NXT_EXPORT void nxt_buf_filter_add(nxt_thread_t *thr, nxt_buf_filter_t *f,
+NXT_EXPORT void nxt_buf_filter_add(nxt_task_t *task, nxt_buf_filter_t *f,
nxt_buf_t *b);
-NXT_EXPORT void nxt_buf_filter(nxt_thread_t *thr, void *obj, void *data);
-NXT_EXPORT void nxt_buf_filter_enqueue(nxt_thread_t *thr, nxt_buf_filter_t *f);
+NXT_EXPORT void nxt_buf_filter(nxt_task_t *task, void *obj, void *data);
+NXT_EXPORT void nxt_buf_filter_enqueue(nxt_task_t *task, nxt_buf_filter_t *f);
#endif /* _NXT_BUF_FILTER_H_INCLUDED_ */
diff --git a/src/nxt_chan.c b/src/nxt_chan.c
index cc6ba786..baa4b9d4 100644
--- a/src/nxt_chan.c
+++ b/src/nxt_chan.c
@@ -7,13 +7,13 @@
#include <nxt_main.h>
-static void nxt_chan_write_handler(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_chan_read_handler(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_chan_read_msg_process(nxt_thread_t *thr, nxt_chan_t *chan,
+static void nxt_chan_write_handler(nxt_task_t *task, void *obj, void *data);
+static void nxt_chan_read_handler(nxt_task_t *task, void *obj, void *data);
+static void nxt_chan_read_msg_process(nxt_task_t *task, nxt_chan_t *chan,
nxt_chan_msg_t *msg, nxt_fd_t fd, nxt_buf_t *b, size_t size);
static nxt_buf_t *nxt_chan_buf_alloc(nxt_chan_t *chan);
static void nxt_chan_buf_free(nxt_chan_t *chan, nxt_buf_t *b);
-static void nxt_chan_error_handler(nxt_thread_t *thr, void *obj, void *data);
+static void nxt_chan_error_handler(nxt_task_t *task, void *obj, void *data);
nxt_chan_t *
@@ -129,13 +129,19 @@ nxt_chan_destroy(nxt_chan_t *chan)
void
-nxt_chan_write_enable(nxt_thread_t *thr, nxt_chan_t *chan)
+nxt_chan_write_enable(nxt_task_t *task, nxt_chan_t *chan)
{
chan->socket.fd = chan->pair[1];
chan->socket.log = &nxt_main_log;
chan->socket.write_ready = 1;
- chan->socket.write_work_queue = &thr->work_queue.main;
+ chan->task.thread = task->thread;
+ chan->task.log = chan->socket.log;
+ chan->task.ident = nxt_task_next_ident();
+
+ chan->socket.task = &chan->task;
+
+ chan->socket.write_work_queue = &task->thread->work_queue.main;
chan->socket.write_handler = nxt_chan_write_handler;
chan->socket.error_handler = nxt_chan_error_handler;
}
@@ -150,10 +156,9 @@ nxt_chan_write_close(nxt_chan_t *chan)
nxt_int_t
-nxt_chan_write(nxt_chan_t *chan, nxt_uint_t type, nxt_fd_t fd, uint32_t stream,
- nxt_buf_t *b)
+nxt_chan_write(nxt_task_t *task, nxt_chan_t *chan, nxt_uint_t type,
+ nxt_fd_t fd, uint32_t stream, nxt_buf_t *b)
{
- nxt_thread_t *thr;
nxt_queue_link_t *link;
nxt_chan_send_msg_t *msg;
@@ -190,8 +195,7 @@ nxt_chan_write(nxt_chan_t *chan, nxt_uint_t type, nxt_fd_t fd, uint32_t stream,
nxt_queue_insert_tail(&chan->messages, &msg->link);
if (chan->socket.write_ready) {
- thr = nxt_thread();
- nxt_chan_write_handler(thr, chan, NULL);
+ nxt_chan_write_handler(task, chan, NULL);
}
return NXT_OK;
@@ -199,7 +203,7 @@ nxt_chan_write(nxt_chan_t *chan, nxt_uint_t type, nxt_fd_t fd, uint32_t stream,
static void
-nxt_chan_write_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_chan_write_handler(nxt_task_t *task, void *obj, void *data)
{
ssize_t n;
nxt_uint_t niob;
@@ -215,7 +219,7 @@ nxt_chan_write_handler(nxt_thread_t *thr, void *obj, void *data)
link = nxt_queue_first(&chan->messages);
if (link == nxt_queue_tail(&chan->messages)) {
- nxt_event_fd_block_write(thr->engine, &chan->socket);
+ nxt_event_fd_block_write(task->thread->engine, &chan->socket);
return;
}
@@ -231,7 +235,7 @@ nxt_chan_write_handler(nxt_thread_t *thr, void *obj, void *data)
sb.size = sizeof(nxt_chan_msg_t);
sb.limit = chan->max_size;
- niob = nxt_sendbuf_mem_coalesce(&sb);
+ niob = nxt_sendbuf_mem_coalesce(task, &sb);
msg->chan_msg.last = sb.last;
@@ -239,13 +243,13 @@ nxt_chan_write_handler(nxt_thread_t *thr, void *obj, void *data)
if (n > 0) {
if (nxt_slow_path((size_t) n != sb.size)) {
- nxt_log_alert(thr->log,
- "chan %d: short write: %z instead of %uz",
- chan->socket.fd, n, sb.size);
+ nxt_log(task, NXT_LOG_CRIT,
+ "chan %d: short write: %z instead of %uz",
+ chan->socket.fd, n, sb.size);
goto fail;
}
- msg->buf = nxt_sendbuf_completion(thr,
+ msg->buf = nxt_sendbuf_completion(task,
chan->socket.write_work_queue,
msg->buf,
n - sizeof(nxt_chan_msg_t));
@@ -279,30 +283,36 @@ nxt_chan_write_handler(nxt_thread_t *thr, void *obj, void *data)
} while (chan->socket.write_ready);
if (nxt_event_fd_is_disabled(chan->socket.write)) {
- nxt_event_fd_enable_write(thr->engine, &chan->socket);
+ nxt_event_fd_enable_write(task->thread->engine, &chan->socket);
}
return;
fail:
- nxt_thread_work_queue_add(thr, &thr->work_queue.main,
- nxt_chan_error_handler,
- &chan->socket, NULL, chan->socket.log);
+ nxt_thread_work_queue_add(task->thread, &task->thread->work_queue.main,
+ nxt_chan_error_handler, task, &chan->socket,
+ NULL);
}
void
-nxt_chan_read_enable(nxt_thread_t *thr, nxt_chan_t *chan)
+nxt_chan_read_enable(nxt_task_t *task, nxt_chan_t *chan)
{
chan->socket.fd = chan->pair[0];
chan->socket.log = &nxt_main_log;
- chan->socket.read_work_queue = &thr->work_queue.main;
+ chan->task.thread = task->thread;
+ chan->task.log = chan->socket.log;
+ chan->task.ident = nxt_task_next_ident();
+
+ chan->socket.task = &chan->task;
+
+ chan->socket.read_work_queue = &task->thread->work_queue.main;
chan->socket.read_handler = nxt_chan_read_handler;
chan->socket.error_handler = nxt_chan_error_handler;
- nxt_event_fd_enable_read(thr->engine, &chan->socket);
+ nxt_event_fd_enable_read(task->thread->engine, &chan->socket);
}
@@ -315,7 +325,7 @@ nxt_chan_read_close(nxt_chan_t *chan)
static void
-nxt_chan_read_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_chan_read_handler(nxt_task_t *task, void *obj, void *data)
{
ssize_t n;
nxt_fd_t fd;
@@ -340,7 +350,7 @@ nxt_chan_read_handler(nxt_thread_t *thr, void *obj, void *data)
n = nxt_socketpair_recv(&chan->socket, &fd, iob, 2);
if (n > 0) {
- nxt_chan_read_msg_process(thr, chan, &msg, fd, b, n);
+ nxt_chan_read_msg_process(task, chan, &msg, fd, b, n);
if (b->mem.pos == b->mem.free) {
@@ -362,30 +372,30 @@ nxt_chan_read_handler(nxt_thread_t *thr, void *obj, void *data)
if (n == NXT_AGAIN) {
nxt_chan_buf_free(chan, b);
- nxt_event_fd_enable_read(thr->engine, &chan->socket);
+ nxt_event_fd_enable_read(task->thread->engine, &chan->socket);
return;
}
/* n == 0 || n == NXT_ERROR */
- nxt_thread_work_queue_add(thr, &thr->work_queue.main,
- nxt_chan_error_handler,
- &chan->socket, NULL, chan->socket.log);
+ nxt_thread_work_queue_add(task->thread, &task->thread->work_queue.main,
+ nxt_chan_error_handler, task,
+ &chan->socket, NULL);
return;
}
}
static void
-nxt_chan_read_msg_process(nxt_thread_t *thr, nxt_chan_t *chan,
+nxt_chan_read_msg_process(nxt_task_t *task, nxt_chan_t *chan,
nxt_chan_msg_t *msg, nxt_fd_t fd, nxt_buf_t *b, size_t size)
{
nxt_buf_t *sync;
nxt_chan_recv_msg_t recv_msg;
if (nxt_slow_path(size < sizeof(nxt_chan_msg_t))) {
- nxt_log_alert(chan->socket.log, "chan %d: too small message:%uz",
- chan->socket.fd, size);
+ nxt_log(chan->socket.task, NXT_LOG_CRIT,
+ "chan %d: too small message:%uz", chan->socket.fd, size);
goto fail;
}
@@ -406,7 +416,7 @@ nxt_chan_read_msg_process(nxt_thread_t *thr, nxt_chan_t *chan,
b->next = sync;
}
- chan->handler(thr, &recv_msg);
+ chan->handler(task, &recv_msg);
return;
@@ -450,7 +460,7 @@ nxt_chan_buf_free(nxt_chan_t *chan, nxt_buf_t *b)
static void
-nxt_chan_error_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_chan_error_handler(nxt_task_t *task, void *obj, void *data)
{
/* TODO */
}
diff --git a/src/nxt_chan.h b/src/nxt_chan.h
index f9550f17..48cd1a9b 100644
--- a/src/nxt_chan.h
+++ b/src/nxt_chan.h
@@ -26,13 +26,15 @@ typedef struct {
typedef struct nxt_chan_recv_msg_s nxt_chan_recv_msg_t;
-typedef void (*nxt_chan_handler_t)(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg);
+typedef void (*nxt_chan_handler_t)(nxt_task_t *task, nxt_chan_recv_msg_t *msg);
typedef struct {
/* Must be the first field. */
nxt_event_fd_t socket;
+ nxt_task_t task;
+
nxt_queue_t messages; /* of nxt_chan_send_msg_t */
/* Maximum size of message part. */
@@ -62,12 +64,12 @@ struct nxt_chan_recv_msg_s {
NXT_EXPORT nxt_chan_t *nxt_chan_alloc(void);
NXT_EXPORT nxt_chan_t *nxt_chan_create(size_t bufsize);
NXT_EXPORT void nxt_chan_destroy(nxt_chan_t *chan);
-NXT_EXPORT void nxt_chan_write_enable(nxt_thread_t *thr, nxt_chan_t *chan);
+NXT_EXPORT void nxt_chan_write_enable(nxt_task_t *task, nxt_chan_t *chan);
NXT_EXPORT void nxt_chan_write_close(nxt_chan_t *chan);
-NXT_EXPORT void nxt_chan_read_enable(nxt_thread_t *thr, nxt_chan_t *chan);
+NXT_EXPORT void nxt_chan_read_enable(nxt_task_t *task, nxt_chan_t *chan);
NXT_EXPORT void nxt_chan_read_close(nxt_chan_t *chan);
-NXT_EXPORT nxt_int_t nxt_chan_write(nxt_chan_t *chan, nxt_uint_t type,
- nxt_fd_t fd, uint32_t stream, nxt_buf_t *b);
+NXT_EXPORT nxt_int_t nxt_chan_write(nxt_task_t *task, nxt_chan_t *chan,
+ nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_buf_t *b);
#endif /* _NXT_UNIX_CHAN_H_INCLUDED_ */
diff --git a/src/nxt_cycle.c b/src/nxt_cycle.c
index 8539bc05..4b6eeb40 100644
--- a/src/nxt_cycle.c
+++ b/src/nxt_cycle.c
@@ -18,14 +18,14 @@ static nxt_int_t nxt_cycle_systemd_listen_sockets(nxt_thread_t *thr,
static nxt_int_t nxt_cycle_event_engines(nxt_thread_t *thr, nxt_cycle_t *cycle);
static nxt_int_t nxt_cycle_processes(nxt_cycle_t *cycle);
static nxt_int_t nxt_cycle_thread_pools(nxt_thread_t *thr, nxt_cycle_t *cycle);
-static void nxt_cycle_start(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_cycle_initial_start(nxt_thread_t *thr, nxt_cycle_t *cycle);
-static void nxt_cycle_conf_test(nxt_thread_t *thr, nxt_cycle_t *cycle);
-static void nxt_single_process_start(nxt_thread_t *thr, nxt_cycle_t *cycle);
-static void nxt_cycle_close_idle_connections(nxt_thread_t *thr);
-static void nxt_cycle_exit(nxt_thread_t *thr, void *obj, void *data);
-static nxt_int_t nxt_cycle_event_engine_change(nxt_thread_t *thr,
+static void nxt_cycle_start(nxt_task_t *task, void *obj, void *data);
+static void nxt_cycle_initial_start(nxt_task_t *task, nxt_cycle_t *cycle);
+static void nxt_single_process_start(nxt_thread_t *thr, nxt_task_t *task,
nxt_cycle_t *cycle);
+static void nxt_cycle_close_idle_connections(nxt_thread_t *thr, nxt_task_t *task);
+static void nxt_cycle_exit(nxt_task_t *task, void *obj, void *data);
+static nxt_int_t nxt_cycle_event_engine_change(nxt_thread_t *thr,
+ nxt_task_t *task, nxt_cycle_t *cycle);
static nxt_int_t nxt_cycle_conf_init(nxt_thread_t *thr, nxt_cycle_t *cycle);
static nxt_int_t nxt_cycle_conf_read_cmd(nxt_thread_t *thr, nxt_cycle_t *cycle);
static nxt_sockaddr_t *nxt_cycle_sockaddr_parse(nxt_str_t *addr,
@@ -36,7 +36,8 @@ static nxt_sockaddr_t *nxt_cycle_sockaddr_inet6_parse(nxt_str_t *addr,
nxt_mem_pool_t *mp, nxt_log_t *log);
static nxt_sockaddr_t *nxt_cycle_sockaddr_inet_parse(nxt_str_t *addr,
nxt_mem_pool_t *mp, nxt_log_t *log);
-static nxt_int_t nxt_cycle_conf_apply(nxt_thread_t *thr, nxt_cycle_t *cycle);
+static nxt_int_t nxt_cycle_conf_apply(nxt_thread_t *thr, nxt_task_t *task,
+ nxt_cycle_t *cycle);
static nxt_int_t nxt_cycle_listen_socket(nxt_cycle_t *cycle);
static nxt_int_t nxt_cycle_hostname(nxt_thread_t *thr, nxt_cycle_t *cycle);
static nxt_int_t nxt_cycle_log_files_init(nxt_cycle_t *cycle);
@@ -49,7 +50,7 @@ static nxt_int_t nxt_cycle_shm_zone_create(nxt_cycle_shm_zone_t *shm_zone);
#if (NXT_THREADS)
static void nxt_cycle_thread_pool_destroy(nxt_thread_t *thr,
- nxt_cycle_t *cycle, nxt_cycle_cont_t cont);
+ nxt_task_t *task, nxt_cycle_t *cycle, nxt_cycle_cont_t cont);
#endif
@@ -57,8 +58,8 @@ nxt_thread_declare_data(nxt_cycle_t *, nxt_thread_cycle_data);
nxt_int_t
-nxt_cycle_create(nxt_thread_t *thr, nxt_cycle_t *previous,
- nxt_cycle_cont_t start, nxt_str_t *config_name, nxt_bool_t test_config)
+nxt_cycle_create(nxt_thread_t *thr, nxt_task_t *task, nxt_cycle_t *previous,
+ nxt_cycle_cont_t start, nxt_str_t *config_name)
{
nxt_int_t ret;
nxt_cycle_t *cycle;
@@ -78,7 +79,6 @@ nxt_cycle_create(nxt_thread_t *thr, nxt_cycle_t *previous,
cycle->mem_pool = mp;
cycle->previous = previous;
cycle->config_name = config_name;
- cycle->test_config = test_config;
if (previous == NULL) {
cycle->prefix = nxt_current_directory(mp);
@@ -148,14 +148,13 @@ nxt_cycle_create(nxt_thread_t *thr, nxt_cycle_t *previous,
nxt_thread_init_data(nxt_thread_cycle_data);
nxt_thread_cycle_set(cycle);
- cycle->start = test_config ? nxt_cycle_conf_test:
- nxt_cycle_initial_start;
+ cycle->start = nxt_cycle_initial_start;
}
nxt_log_debug(thr->log, "new cycle: %p", cycle);
nxt_thread_work_queue_add(thr, &thr->work_queue.main, nxt_cycle_start,
- cycle, NULL, &nxt_main_log);
+ task, cycle, NULL);
return NXT_OK;
@@ -410,31 +409,31 @@ nxt_cycle_thread_pools(nxt_thread_t *thr, nxt_cycle_t *cycle)
static void
-nxt_cycle_start(nxt_thread_t *thr, void *obj, void *data)
+nxt_cycle_start(nxt_task_t *task, void *obj, void *data)
{
nxt_uint_t i;
nxt_cycle_t *cycle;
cycle = obj;
- nxt_log_debug(thr->log, "cycle conf done");
+ nxt_debug(task, "cycle conf done");
- nxt_mem_pool_debug_lock(cycle->mem_pool, nxt_thread_tid(thr));
+ nxt_mem_pool_debug_lock(cycle->mem_pool, nxt_thread_tid(task->thread));
- thr->log->ctx_handler = NULL;
- thr->log->ctx = NULL;
+ task->thread->log->ctx_handler = NULL;
+ task->thread->log->ctx = NULL;
- if (nxt_cycle_conf_init(thr, cycle) != NXT_OK) {
+ if (nxt_cycle_conf_init(task->thread, cycle) != NXT_OK) {
goto fail;
}
for (i = 0; i < nxt_init_modules_n; i++) {
- if (nxt_init_modules[i](thr, cycle) != NXT_OK) {
+ if (nxt_init_modules[i](task->thread, cycle) != NXT_OK) {
goto fail;
}
}
- if (nxt_cycle_conf_apply(thr, cycle) != NXT_OK) {
+ if (nxt_cycle_conf_apply(task->thread, task, cycle) != NXT_OK) {
goto fail;
}
@@ -447,11 +446,11 @@ nxt_cycle_start(nxt_thread_t *thr, void *obj, void *data)
* processes, because thread pool semaphores will stick in
* locked state in new processes after fork().
*/
- nxt_cycle_thread_pool_destroy(thr, cycle, cycle->start);
+ nxt_cycle_thread_pool_destroy(task->thread, task, cycle, cycle->start);
#else
- cycle->start(thr, cycle);
+ cycle->start(task->thread, cycle);
#endif
@@ -459,16 +458,19 @@ nxt_cycle_start(nxt_thread_t *thr, void *obj, void *data)
fail:
- nxt_cycle_quit(thr, cycle);
+ nxt_cycle_quit(task, cycle);
}
static void
-nxt_cycle_initial_start(nxt_thread_t *thr, nxt_cycle_t *cycle)
+nxt_cycle_initial_start(nxt_task_t *task, nxt_cycle_t *cycle)
{
nxt_int_t ret;
+ nxt_thread_t *thr;
const nxt_event_set_ops_t *event_set;
+ thr = task->thread;
+
if (cycle->inherited_sockets == NULL && cycle->daemon) {
if (nxt_process_daemon() != NXT_OK) {
@@ -486,7 +488,7 @@ nxt_cycle_initial_start(nxt_thread_t *thr, nxt_cycle_t *cycle)
goto fail;
}
- ret = nxt_event_engine_change(thr, event_set, cycle->batch);
+ ret = nxt_event_engine_change(thr, task, event_set, cycle->batch);
if (ret != NXT_OK) {
goto fail;
}
@@ -497,39 +499,31 @@ nxt_cycle_initial_start(nxt_thread_t *thr, nxt_cycle_t *cycle)
goto fail;
}
- if (nxt_cycle_event_engine_change(thr, cycle) != NXT_OK) {
+ if (nxt_cycle_event_engine_change(thr, task, cycle) != NXT_OK) {
goto fail;
}
thr->engine->max_connections = cycle->engine_connections;
if (cycle->master_process) {
- if (nxt_master_process_start(thr, cycle) != NXT_ERROR) {
+ if (nxt_master_process_start(thr, task, cycle) != NXT_ERROR) {
return;
}
} else {
- nxt_single_process_start(thr, cycle);
+ nxt_single_process_start(thr, task, cycle);
return;
}
fail:
- nxt_cycle_quit(thr, cycle);
+ nxt_cycle_quit(task, cycle);
}
static void
-nxt_cycle_conf_test(nxt_thread_t *thr, nxt_cycle_t *cycle)
-{
- (void) nxt_cycle_pid_file_create(cycle->pid_file, cycle->test_config);
-
- nxt_cycle_quit(thr, cycle);
-}
-
-
-static void
-nxt_single_process_start(nxt_thread_t *thr, nxt_cycle_t *cycle)
+nxt_single_process_start(nxt_thread_t *thr, nxt_task_t *task,
+ nxt_cycle_t *cycle)
{
#if (NXT_THREADS)
nxt_int_t ret;
@@ -538,7 +532,7 @@ nxt_single_process_start(nxt_thread_t *thr, nxt_cycle_t *cycle)
60000 * 1000000LL);
if (nxt_slow_path(ret != NXT_OK)) {
- nxt_cycle_quit(thr, cycle);
+ nxt_cycle_quit(task, cycle);
return;
}
@@ -546,18 +540,21 @@ nxt_single_process_start(nxt_thread_t *thr, nxt_cycle_t *cycle)
cycle->type = NXT_PROCESS_SINGLE;
- nxt_cycle_listen_sockets_enable(thr, cycle);
+ nxt_cycle_listen_sockets_enable(task, cycle);
return;
}
void
-nxt_cycle_quit(nxt_thread_t *thr, nxt_cycle_t *cycle)
+nxt_cycle_quit(nxt_task_t *task, nxt_cycle_t *cycle)
{
- nxt_bool_t done;
+ nxt_bool_t done;
+ nxt_thread_t *thr;
+
+ thr = task->thread;
- nxt_log_debug(thr->log, "exiting");
+ nxt_debug(task, "exiting");
if (cycle == NULL) {
cycle = nxt_thread_cycle();
@@ -571,29 +568,29 @@ nxt_cycle_quit(nxt_thread_t *thr, nxt_cycle_t *cycle)
#if (NXT_THREADS)
if (!nxt_array_is_empty(cycle->thread_pools)) {
- nxt_cycle_thread_pool_destroy(thr, cycle, nxt_cycle_quit);
+ nxt_cycle_thread_pool_destroy(thr, task, cycle, nxt_cycle_quit);
done = 0;
}
#endif
if (!cycle->test_config && cycle->type == NXT_PROCESS_MASTER) {
- nxt_master_stop_worker_processes(cycle);
+ nxt_master_stop_worker_processes(task, cycle);
done = 0;
}
}
- nxt_cycle_close_idle_connections(thr);
+ nxt_cycle_close_idle_connections(thr, task);
if (done) {
nxt_thread_work_queue_add(thr, &thr->work_queue.main, nxt_cycle_exit,
- cycle, NULL, &nxt_main_log);
+ task, cycle, NULL);
}
}
static void
-nxt_cycle_close_idle_connections(nxt_thread_t *thr)
+nxt_cycle_close_idle_connections(nxt_thread_t *thr, nxt_task_t *task)
{
nxt_queue_t *idle;
nxt_queue_link_t *link, *next;
@@ -612,14 +609,14 @@ nxt_cycle_close_idle_connections(nxt_thread_t *thr)
if (!c->socket.read_ready) {
nxt_queue_remove(link);
- nxt_event_conn_close(thr, c);
+ nxt_event_conn_close(task, c);
}
}
}
static void
-nxt_cycle_exit(nxt_thread_t *thr, void *obj, void *data)
+nxt_cycle_exit(nxt_task_t *task, void *obj, void *data)
{
nxt_cycle_t *cycle;
@@ -627,7 +624,7 @@ nxt_cycle_exit(nxt_thread_t *thr, void *obj, void *data)
#if (NXT_THREADS)
- nxt_log_debug(thr->log, "thread pools: %d", cycle->thread_pools->nelts);
+ nxt_debug(task, "thread pools: %d", cycle->thread_pools->nelts);
if (!nxt_array_is_empty(cycle->thread_pools)) {
return;
@@ -639,11 +636,11 @@ nxt_cycle_exit(nxt_thread_t *thr, void *obj, void *data)
nxt_cycle_pid_file_delete(cycle);
}
- if (!thr->engine->event->signal_support) {
- nxt_event_engine_signals_stop(thr->engine);
+ if (!task->thread->engine->event->signal_support) {
+ nxt_event_engine_signals_stop(task->thread->engine);
}
- nxt_log_debug(thr->log, "exit");
+ nxt_debug(task, "exit");
exit(0);
nxt_unreachable();
@@ -651,7 +648,8 @@ nxt_cycle_exit(nxt_thread_t *thr, void *obj, void *data)
static nxt_int_t
-nxt_cycle_event_engine_change(nxt_thread_t *thr, nxt_cycle_t *cycle)
+nxt_cycle_event_engine_change(nxt_thread_t *thr, nxt_task_t *task,
+ nxt_cycle_t *cycle)
{
const nxt_event_set_ops_t *event_set;
@@ -663,7 +661,7 @@ nxt_cycle_event_engine_change(nxt_thread_t *thr, nxt_cycle_t *cycle)
event_set = nxt_service_get(cycle->services, "engine", cycle->engine);
if (event_set != NULL) {
- return nxt_event_engine_change(thr, event_set, cycle->batch);
+ return nxt_event_engine_change(thr, task, event_set, cycle->batch);
}
return NXT_ERROR;
@@ -686,8 +684,7 @@ nxt_cycle_event_engine_free(nxt_cycle_t *cycle)
#if (NXT_THREADS)
static void nxt_cycle_thread_pool_init(void);
-static void nxt_cycle_thread_pool_exit(nxt_thread_t *thr, void *obj,
- void *data);
+static void nxt_cycle_thread_pool_exit(nxt_task_t *task, void *obj, void *data);
nxt_int_t
@@ -715,8 +712,8 @@ nxt_cycle_thread_pool_create(nxt_thread_t *thr, nxt_cycle_t *cycle,
static void
-nxt_cycle_thread_pool_destroy(nxt_thread_t *thr, nxt_cycle_t *cycle,
- nxt_cycle_cont_t cont)
+nxt_cycle_thread_pool_destroy(nxt_thread_t *thr, nxt_task_t *task,
+ nxt_cycle_t *cycle, nxt_cycle_cont_t cont)
{
nxt_uint_t n;
nxt_thread_pool_t **tp;
@@ -726,7 +723,7 @@ nxt_cycle_thread_pool_destroy(nxt_thread_t *thr, nxt_cycle_t *cycle,
n = cycle->thread_pools->nelts;
if (n == 0) {
- cont(thr, cycle);
+ cont(task, cycle);
return;
}
@@ -751,7 +748,7 @@ nxt_cycle_thread_pool_init(void)
static void
-nxt_cycle_thread_pool_exit(nxt_thread_t *thr, void *obj, void *data)
+nxt_cycle_thread_pool_exit(nxt_task_t *task, void *obj, void *data)
{
nxt_uint_t i, n;
nxt_cycle_t *cycle;
@@ -770,7 +767,7 @@ nxt_cycle_thread_pool_exit(nxt_thread_t *thr, void *obj, void *data)
thread_pools = cycle->thread_pools->elts;
n = cycle->thread_pools->nelts;
- nxt_log_debug(thr->log, "thread pools: %ui, cycle %p", n, cycle);
+ nxt_debug(task, "thread pools: %ui, cycle %p", n, cycle);
for (i = 0; i < n; i++) {
@@ -779,7 +776,7 @@ nxt_cycle_thread_pool_exit(nxt_thread_t *thr, void *obj, void *data)
if (n == 1) {
/* The last thread pool. */
- cycle->continuation(thr, cycle);
+ cycle->continuation(task, cycle);
}
return;
@@ -1239,7 +1236,7 @@ invalid_addr:
static nxt_int_t
-nxt_cycle_conf_apply(nxt_thread_t *thr, nxt_cycle_t *cycle)
+nxt_cycle_conf_apply(nxt_thread_t *thr, nxt_task_t *task, nxt_cycle_t *cycle)
{
if (nxt_cycle_log_files_create(cycle) != NXT_OK) {
return NXT_ERROR;
@@ -1249,7 +1246,7 @@ nxt_cycle_conf_apply(nxt_thread_t *thr, nxt_cycle_t *cycle)
return NXT_ERROR;
}
- if (nxt_cycle_event_engine_change(thr, cycle) != NXT_OK) {
+ if (nxt_cycle_event_engine_change(thr, task, cycle) != NXT_OK) {
return NXT_ERROR;
}
@@ -1571,7 +1568,7 @@ nxt_cycle_listen_sockets_close(nxt_cycle_t *cycle)
nxt_int_t
-nxt_cycle_listen_sockets_enable(nxt_thread_t *thr, nxt_cycle_t *cycle)
+nxt_cycle_listen_sockets_enable(nxt_task_t *task, nxt_cycle_t *cycle)
{
nxt_uint_t i, n;
nxt_listen_socket_t *ls;
@@ -1580,7 +1577,7 @@ nxt_cycle_listen_sockets_enable(nxt_thread_t *thr, nxt_cycle_t *cycle)
n = cycle->listen_sockets->nelts;
for (i = 0; i < n; i++) {
- if (nxt_event_conn_listen(thr, &ls[i]) != NXT_OK) {
+ if (nxt_event_conn_listen(task, &ls[i]) != NXT_OK) {
return NXT_ERROR;
}
}
diff --git a/src/nxt_cycle.h b/src/nxt_cycle.h
index 18c944b4..f2b0e5a4 100644
--- a/src/nxt_cycle.h
+++ b/src/nxt_cycle.h
@@ -17,7 +17,7 @@ typedef enum {
typedef struct nxt_cycle_s nxt_cycle_t;
-typedef void (*nxt_cycle_cont_t)(nxt_thread_t *thr, nxt_cycle_t *cycle);
+typedef void (*nxt_cycle_cont_t)(nxt_task_t *task, nxt_cycle_t *cycle);
struct nxt_cycle_s {
@@ -120,9 +120,9 @@ nxt_thread_cycle(void)
}
-nxt_int_t nxt_cycle_create(nxt_thread_t *thr, nxt_cycle_t *previous,
- nxt_cycle_cont_t start, nxt_str_t *config_name, nxt_bool_t test_config);
-void nxt_cycle_quit(nxt_thread_t *thr, nxt_cycle_t *cycle);
+nxt_int_t nxt_cycle_create(nxt_thread_t *thr, nxt_task_t *task,
+ nxt_cycle_t *previous, nxt_cycle_cont_t start, nxt_str_t *config_name);
+void nxt_cycle_quit(nxt_task_t *task, nxt_cycle_t *cycle);
void nxt_cycle_event_engine_free(nxt_cycle_t *cycle);
@@ -138,8 +138,7 @@ nxt_int_t nxt_cycle_pid_file_create(nxt_file_name_t *pid_file, nxt_bool_t test);
nxt_listen_socket_t *nxt_cycle_listen_socket_add(nxt_cycle_t *cycle,
nxt_sockaddr_t *sa);
-nxt_int_t nxt_cycle_listen_sockets_enable(nxt_thread_t *thr,
- nxt_cycle_t *cycle);
+nxt_int_t nxt_cycle_listen_sockets_enable(nxt_task_t *task, nxt_cycle_t *cycle);
nxt_file_t *nxt_cycle_log_file_add(nxt_cycle_t *cycle, nxt_str_t *name);
nxt_int_t nxt_cycle_shm_zone_add(nxt_cycle_t *cycle, nxt_str_t *name,
diff --git a/src/nxt_epoll.c b/src/nxt_epoll.c
index 65e9eb8d..0fe81092 100644
--- a/src/nxt_epoll.c
+++ b/src/nxt_epoll.c
@@ -65,37 +65,37 @@ static void nxt_epoll_enable_accept(nxt_event_set_t *event_set,
nxt_event_fd_t *ev);
static void nxt_epoll_change(nxt_event_set_t *event_set, nxt_event_fd_t *ev,
int op, uint32_t events);
-static nxt_int_t nxt_epoll_commit_changes(nxt_thread_t *thr,
+static nxt_int_t nxt_epoll_commit_changes(nxt_task_t *task,
nxt_epoll_event_set_t *es);
-static void nxt_epoll_error_handler(nxt_thread_t *thr, void *obj,
+static void nxt_epoll_error_handler(nxt_task_t *task, void *obj,
void *data);
#if (NXT_HAVE_SIGNALFD)
static nxt_int_t nxt_epoll_add_signal(nxt_epoll_event_set_t *es,
nxt_event_signals_t *signals);
-static void nxt_epoll_signalfd_handler(nxt_thread_t *thr, void *obj,
+static void nxt_epoll_signalfd_handler(nxt_task_t *task, void *obj,
void *data);
#endif
#if (NXT_HAVE_EVENTFD)
static nxt_int_t nxt_epoll_enable_post(nxt_event_set_t *event_set,
nxt_work_handler_t handler);
-static void nxt_epoll_eventfd_handler(nxt_thread_t *thr, void *obj,
+static void nxt_epoll_eventfd_handler(nxt_task_t *task, void *obj,
void *data);
static void nxt_epoll_signal(nxt_event_set_t *event_set, nxt_uint_t signo);
#endif
-static void nxt_epoll_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
+static void nxt_epoll_poll(nxt_task_t *task, nxt_event_set_t *event_set,
nxt_msec_t timeout);
#if (NXT_HAVE_ACCEPT4)
-static void nxt_epoll_event_conn_io_accept4(nxt_thread_t *thr, void *obj,
+static void nxt_epoll_event_conn_io_accept4(nxt_task_t *task, void *obj,
void *data);
#endif
#if (NXT_HAVE_EPOLL_EDGE)
-static void nxt_epoll_edge_event_conn_io_connect(nxt_thread_t *thr, void *obj,
+static void nxt_epoll_edge_event_conn_io_connect(nxt_task_t *task, void *obj,
void *data);
-static void nxt_epoll_edge_event_conn_connected(nxt_thread_t *thr, void *obj,
+static void nxt_epoll_edge_event_conn_connected(nxt_task_t *task, void *obj,
void *data);
static ssize_t nxt_epoll_edge_event_conn_io_recvbuf(nxt_event_conn_t *c,
nxt_buf_t *b);
@@ -427,7 +427,7 @@ nxt_epoll_close(nxt_event_set_t *event_set, nxt_event_fd_t *ev)
es = &event_set->epoll;
if (es->nchanges != 0) {
- (void) nxt_epoll_commit_changes(nxt_thread(), &event_set->epoll);
+ (void) nxt_epoll_commit_changes(ev->task, &event_set->epoll);
}
}
@@ -614,7 +614,7 @@ nxt_epoll_change(nxt_event_set_t *event_set, nxt_event_fd_t *ev, int op,
es->epoll, ev->fd, op, events);
if (es->nchanges >= es->mchanges) {
- (void) nxt_epoll_commit_changes(nxt_thread(), es);
+ (void) nxt_epoll_commit_changes(ev->task, es);
}
ch = &es->changes[es->nchanges++];
@@ -626,13 +626,13 @@ nxt_epoll_change(nxt_event_set_t *event_set, nxt_event_fd_t *ev, int op,
static nxt_int_t
-nxt_epoll_commit_changes(nxt_thread_t *thr, nxt_epoll_event_set_t *es)
+nxt_epoll_commit_changes(nxt_task_t *task, nxt_epoll_event_set_t *es)
{
nxt_int_t ret;
nxt_event_fd_t *ev;
nxt_epoll_change_t *ch, *end;
- nxt_log_debug(thr->log, "epoll %d changes:%ui", es->epoll, es->nchanges);
+ nxt_debug(task, "epoll %d changes:%ui", es->epoll, es->nchanges);
ret = NXT_OK;
ch = es->changes;
@@ -641,16 +641,17 @@ nxt_epoll_commit_changes(nxt_thread_t *thr, nxt_epoll_event_set_t *es)
do {
ev = ch->event.data.ptr;
- nxt_log_debug(ev->log, "epoll_ctl(%d): fd:%d op:%d ev:%XD",
- es->epoll, ch->fd, ch->op, ch->event.events);
+ nxt_debug(ev->task, "epoll_ctl(%d): fd:%d op:%d ev:%XD",
+ es->epoll, ch->fd, ch->op, ch->event.events);
if (epoll_ctl(es->epoll, ch->op, ch->fd, &ch->event) != 0) {
- nxt_log_alert(ev->log, "epoll_ctl(%d, %d, %d) failed %E",
- es->epoll, ch->op, ch->fd, nxt_errno);
+ nxt_log(ev->task, NXT_LOG_CRIT, "epoll_ctl(%d, %d, %d) failed %E",
+ es->epoll, ch->op, ch->fd, nxt_errno);
- nxt_thread_work_queue_add(thr, &thr->work_queue.main,
+ nxt_thread_work_queue_add(task->thread,
+ &task->thread->work_queue.main,
nxt_epoll_error_handler,
- ev, ev->data, ev->log);
+ ev->task, ev, ev->data);
ret = NXT_ERROR;
}
@@ -666,7 +667,7 @@ nxt_epoll_commit_changes(nxt_thread_t *thr, nxt_epoll_event_set_t *es)
static void
-nxt_epoll_error_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_epoll_error_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_event_fd_t *ev;
@@ -675,7 +676,7 @@ nxt_epoll_error_handler(nxt_thread_t *thr, void *obj, void *data)
ev->read = NXT_EVENT_INACTIVE;
ev->write = NXT_EVENT_INACTIVE;
- ev->error_handler(thr, ev, data);
+ ev->error_handler(ev->task, ev, data);
}
@@ -685,6 +686,7 @@ static nxt_int_t
nxt_epoll_add_signal(nxt_epoll_event_set_t *es, nxt_event_signals_t *signals)
{
int fd;
+ nxt_thread_t *thr;
struct epoll_event ee;
if (sigprocmask(SIG_BLOCK, &signals->sigmask, NULL) != 0) {
@@ -722,6 +724,9 @@ nxt_epoll_add_signal(nxt_epoll_event_set_t *es, nxt_event_signals_t *signals)
es->signalfd.read_handler = nxt_epoll_signalfd_handler;
es->signalfd.log = &nxt_main_log;
+ thr = nxt_thread();
+ es->signalfd.task = &thr->engine->task;
+
ee.events = EPOLLIN;
ee.data.ptr = &es->signalfd;
@@ -737,7 +742,7 @@ nxt_epoll_add_signal(nxt_epoll_event_set_t *es, nxt_event_signals_t *signals)
static void
-nxt_epoll_signalfd_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_epoll_signalfd_handler(nxt_task_t *task, void *obj, void *data)
{
int n;
nxt_event_fd_t *ev;
@@ -747,20 +752,20 @@ nxt_epoll_signalfd_handler(nxt_thread_t *thr, void *obj, void *data)
ev = obj;
handler = data;
- nxt_log_debug(thr->log, "signalfd handler");
+ nxt_debug(task, "signalfd handler");
n = read(ev->fd, &sfd, sizeof(struct signalfd_siginfo));
- nxt_log_debug(thr->log, "read signalfd(%d): %d", ev->fd, n);
+ nxt_debug(task, "read signalfd(%d): %d", ev->fd, n);
if (n != sizeof(struct signalfd_siginfo)) {
- nxt_log_alert(thr->log, "read signalfd(%d) failed %E",
- ev->fd, nxt_errno);
+ nxt_log(task, NXT_LOG_CRIT, "read signalfd(%d) failed %E",
+ ev->fd, nxt_errno);
}
- nxt_log_debug(thr->log, "signalfd(%d) signo:%d", ev->fd, sfd.ssi_signo);
+ nxt_debug(task, "signalfd(%d) signo:%d", ev->fd, sfd.ssi_signo);
- handler(thr, (void *) (uintptr_t) sfd.ssi_signo, NULL);
+ handler(task, (void *) (uintptr_t) sfd.ssi_signo, NULL);
}
#endif
@@ -771,6 +776,7 @@ nxt_epoll_signalfd_handler(nxt_thread_t *thr, void *obj, void *data)
static nxt_int_t
nxt_epoll_enable_post(nxt_event_set_t *event_set, nxt_work_handler_t handler)
{
+ nxt_thread_t *thr;
struct epoll_event ee;
nxt_epoll_event_set_t *es;
@@ -804,6 +810,9 @@ nxt_epoll_enable_post(nxt_event_set_t *event_set, nxt_work_handler_t handler)
es->eventfd.data = es;
es->eventfd.log = &nxt_main_log;
+ thr = nxt_thread();
+ es->eventfd.task = &thr->engine->task;
+
ee.events = EPOLLIN | EPOLLET;
ee.data.ptr = &es->eventfd;
@@ -819,7 +828,7 @@ nxt_epoll_enable_post(nxt_event_set_t *event_set, nxt_work_handler_t handler)
static void
-nxt_epoll_eventfd_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_epoll_eventfd_handler(nxt_task_t *task, void *obj, void *data)
{
int n;
uint64_t events;
@@ -827,7 +836,7 @@ nxt_epoll_eventfd_handler(nxt_thread_t *thr, void *obj, void *data)
es = data;
- nxt_log_debug(thr->log, "eventfd handler, times:%ui", es->neventfd);
+ nxt_debug(task, "eventfd handler, times:%ui", es->neventfd);
/*
* The maximum value after write() to a eventfd() descriptor will
@@ -843,16 +852,15 @@ nxt_epoll_eventfd_handler(nxt_thread_t *thr, void *obj, void *data)
n = read(es->eventfd.fd, &events, sizeof(uint64_t));
- nxt_log_debug(thr->log, "read(%d): %d events:%uL",
- es->eventfd.fd, n, events);
+ nxt_debug(task, "read(%d): %d events:%uL", es->eventfd.fd, n, events);
if (n != sizeof(uint64_t)) {
- nxt_log_alert(thr->log, "read eventfd(%d) failed %E",
- es->eventfd.fd, nxt_errno);
+ nxt_log(task, NXT_LOG_CRIT, "read eventfd(%d) failed %E",
+ es->eventfd.fd, nxt_errno);
}
}
- es->post_handler(thr, NULL, NULL);
+ es->post_handler(task, NULL, NULL);
}
@@ -881,7 +889,7 @@ nxt_epoll_signal(nxt_event_set_t *event_set, nxt_uint_t signo)
static void
-nxt_epoll_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
+nxt_epoll_poll(nxt_task_t *task, nxt_event_set_t *event_set,
nxt_msec_t timeout)
{
int nevents;
@@ -897,26 +905,25 @@ nxt_epoll_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
es = &event_set->epoll;
if (es->nchanges != 0) {
- if (nxt_epoll_commit_changes(thr, es) != NXT_OK) {
+ if (nxt_epoll_commit_changes(task, es) != NXT_OK) {
/* Error handlers have been enqueued on failure. */
timeout = 0;
}
}
- nxt_log_debug(thr->log, "epoll_wait(%d) timeout:%M", es->epoll, timeout);
+ nxt_debug(task, "epoll_wait(%d) timeout:%M", es->epoll, timeout);
nevents = epoll_wait(es->epoll, es->events, es->mevents, timeout);
err = (nevents == -1) ? nxt_errno : 0;
- nxt_thread_time_update(thr);
+ nxt_thread_time_update(task->thread);
- nxt_log_debug(thr->log, "epoll_wait(%d): %d", es->epoll, nevents);
+ nxt_debug(task, "epoll_wait(%d): %d", es->epoll, nevents);
if (nevents == -1) {
level = (err == NXT_EINTR) ? NXT_LOG_INFO : NXT_LOG_ALERT;
- nxt_log_error(level, thr->log, "epoll_wait(%d) failed %E",
- es->epoll, err);
+ nxt_log(task, level, "epoll_wait(%d) failed %E", es->epoll, err);
return;
}
@@ -926,8 +933,8 @@ nxt_epoll_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
events = event->events;
ev = event->data.ptr;
- nxt_log_debug(ev->log, "epoll: fd:%d ev:%04XD d:%p rd:%d wr:%d",
- ev->fd, events, ev, ev->read, ev->write);
+ nxt_debug(ev->task, "epoll: fd:%d ev:%04XD d:%p rd:%d wr:%d",
+ ev->fd, events, ev, ev->read, ev->write);
/*
* On error epoll may set EPOLLERR and EPOLLHUP only without EPOLLIN or
@@ -953,9 +960,9 @@ nxt_epoll_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
error = 0;
- nxt_thread_work_queue_add(thr, ev->read_work_queue,
+ nxt_thread_work_queue_add(task->thread, ev->read_work_queue,
ev->read_handler,
- ev, ev->data, ev->log);
+ ev->task, ev, ev->data);
} else if (event_set->epoll.mode == 0) {
/* Level-triggered mode. */
@@ -974,9 +981,9 @@ nxt_epoll_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
error = 0;
- nxt_thread_work_queue_add(thr, ev->write_work_queue,
+ nxt_thread_work_queue_add(task->thread, ev->write_work_queue,
ev->write_handler,
- ev, ev->data, ev->log);
+ ev->task, ev, ev->data);
} else if (event_set->epoll.mode == 0) {
/* Level-triggered mode. */
@@ -995,7 +1002,7 @@ nxt_epoll_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
#if (NXT_HAVE_ACCEPT4)
static void
-nxt_epoll_event_conn_io_accept4(nxt_thread_t *thr, void *obj, void *data)
+nxt_epoll_event_conn_io_accept4(nxt_task_t *task, void *obj, void *data)
{
socklen_t len;
nxt_socket_t s;
@@ -1024,13 +1031,13 @@ nxt_epoll_event_conn_io_accept4(nxt_thread_t *thr, void *obj, void *data)
if (s != -1) {
c->socket.fd = s;
- nxt_log_debug(thr->log, "accept4(%d): %d", cls->socket.fd, s);
+ nxt_debug(task, "accept4(%d): %d", cls->socket.fd, s);
- nxt_event_conn_accept(thr, cls, c);
+ nxt_event_conn_accept(task, cls, c);
return;
}
- nxt_event_conn_accept_error(thr, cls, "accept4", nxt_errno);
+ nxt_event_conn_accept_error(task, cls, "accept4", nxt_errno);
}
#endif
@@ -1049,8 +1056,7 @@ nxt_epoll_event_conn_io_accept4(nxt_thread_t *thr, void *obj, void *data)
*/
static void
-nxt_epoll_edge_event_conn_io_connect(nxt_thread_t *thr, void *obj,
- void *data)
+nxt_epoll_edge_event_conn_io_connect(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_work_handler_t handler;
@@ -1071,9 +1077,9 @@ nxt_epoll_edge_event_conn_io_connect(nxt_thread_t *thr, void *obj,
c->socket.write_handler = nxt_epoll_edge_event_conn_connected;
c->socket.error_handler = nxt_event_conn_connect_error;
- nxt_event_conn_timer(thr->engine, c, state, &c->write_timer);
+ nxt_event_conn_timer(task->thread->engine, c, state, &c->write_timer);
- nxt_epoll_enable(thr->engine->event_set, &c->socket);
+ nxt_epoll_enable(task->thread->engine->event_set, &c->socket);
c->socket.read = NXT_EVENT_BLOCKED;
return;
@@ -1115,18 +1121,19 @@ nxt_epoll_edge_event_conn_io_connect(nxt_thread_t *thr, void *obj,
break;
}
- nxt_event_conn_io_handle(thr, c->write_work_queue, handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue, handler,
+ task, c, data);
}
static void
-nxt_epoll_edge_event_conn_connected(nxt_thread_t *thr, void *obj, void *data)
+nxt_epoll_edge_event_conn_connected(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
c = obj;
- nxt_log_debug(thr->log, "epoll event conn connected fd:%d", c->socket.fd);
+ nxt_debug(task, "epoll event conn connected fd:%d", c->socket.fd);
if (!c->socket.epoll_error) {
c->socket.write = NXT_EVENT_BLOCKED;
@@ -1135,12 +1142,12 @@ nxt_epoll_edge_event_conn_connected(nxt_thread_t *thr, void *obj, void *data)
nxt_event_timer_disable(&c->write_timer);
}
- nxt_event_conn_io_handle(thr, c->write_work_queue,
- c->write_state->ready_handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue,
+ c->write_state->ready_handler, task, c, data);
return;
}
- nxt_event_conn_connect_test(thr, c, data);
+ nxt_event_conn_connect_test(task, c, data);
}
diff --git a/src/nxt_event_conn.c b/src/nxt_event_conn.c
index a516bbac..6c4fa949 100644
--- a/src/nxt_event_conn.c
+++ b/src/nxt_event_conn.c
@@ -7,9 +7,9 @@
#include <nxt_main.h>
-static void nxt_event_conn_shutdown_socket(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_shutdown_socket(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_close_socket(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_close_socket(nxt_task_t *task, void *obj,
void *data);
@@ -50,9 +50,8 @@ nxt_event_conn_io_t nxt_unix_event_conn_io = {
nxt_event_conn_t *
nxt_event_conn_create(nxt_mem_pool_t *mp, nxt_log_t *log)
{
- nxt_thread_t *thr;
- nxt_event_conn_t *c;
- static nxt_atomic_t ident = 1;
+ nxt_thread_t *thr;
+ nxt_event_conn_t *c;
c = nxt_mem_zalloc(mp, sizeof(nxt_event_conn_t));
if (nxt_slow_path(c == NULL)) {
@@ -69,12 +68,19 @@ nxt_event_conn_create(nxt_mem_pool_t *mp, nxt_log_t *log)
/* The while loop skips possible uint32_t overflow. */
while (c->log.ident == 0) {
- c->log.ident = (uint32_t) nxt_atomic_fetch_add(&ident, 1);
+ c->log.ident = nxt_task_next_ident();
}
thr = nxt_thread();
thr->engine->connections++;
+ c->task.thread = thr;
+ c->task.log = &c->log;
+ c->task.ident = c->log.ident;
+ c->socket.task = &c->task;
+ c->read_timer.task = &c->task;
+ c->write_timer.task = &c->task;
+
c->io = thr->engine->event->io;
c->max_chunk = NXT_INT32_T_MAX;
c->sendfile = NXT_CONN_SENDFILE_UNSET;
@@ -92,7 +98,7 @@ nxt_event_conn_create(nxt_mem_pool_t *mp, nxt_log_t *log)
void
-nxt_event_conn_io_shutdown(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_io_shutdown(nxt_task_t *task, void *obj, void *data)
{
int ret;
socklen_t len;
@@ -101,12 +107,12 @@ nxt_event_conn_io_shutdown(nxt_thread_t *thr, void *obj, void *data)
c = obj;
- nxt_log_debug(thr->log, "event conn shutdown");
+ nxt_debug(task, "event conn shutdown");
if (c->socket.timedout) {
/*
- * A reset of timed out connection on close
- * to release kernel memory associated with socket.
+ * Resetting of timed out connection on close
+ * releases kernel memory associated with socket.
* This also causes sending TCP/IP RST to a peer.
*/
linger.l_onoff = 1;
@@ -116,50 +122,54 @@ nxt_event_conn_io_shutdown(nxt_thread_t *thr, void *obj, void *data)
ret = setsockopt(c->socket.fd, SOL_SOCKET, SO_LINGER, &linger, len);
if (nxt_slow_path(ret != 0)) {
- nxt_log_error(NXT_LOG_CRIT, thr->log,
- "setsockopt(%d, SO_LINGER) failed %E",
- c->socket.fd, nxt_socket_errno);
+ nxt_log(task, NXT_LOG_CRIT, "setsockopt(%d, SO_LINGER) failed %E",
+ c->socket.fd, nxt_socket_errno);
}
}
- c->write_state->close_handler(thr, c, data);
+ c->write_state->close_handler(task, c, data);
}
void
-nxt_event_conn_close(nxt_thread_t *thr, nxt_event_conn_t *c)
+nxt_event_conn_close(nxt_task_t *task, nxt_event_conn_t *c)
{
+ nxt_thread_t *thr;
nxt_work_queue_t *wq;
+ nxt_event_engine_t *engine;
nxt_work_handler_t handler;
- nxt_log_debug(thr->log, "event conn close fd:%d", c->socket.fd);
+ nxt_debug(task, "event conn close fd:%d", c->socket.fd);
+
+ thr = task->thread;
nxt_thread_work_queue_drop(thr, c);
nxt_thread_work_queue_drop(thr, &c->read_timer);
nxt_thread_work_queue_drop(thr, &c->write_timer);
- nxt_event_timer_delete(thr->engine, &c->read_timer);
- nxt_event_timer_delete(thr->engine, &c->write_timer);
+ engine = thr->engine;
+
+ nxt_event_timer_delete(engine, &c->read_timer);
+ nxt_event_timer_delete(engine, &c->write_timer);
- nxt_event_fd_close(thr->engine, &c->socket);
- thr->engine->connections--;
+ nxt_event_fd_close(engine, &c->socket);
+ engine->connections--;
- nxt_log_debug(thr->log, "event connections: %uD", thr->engine->connections);
+ nxt_debug(task, "event connections: %uD", engine->connections);
- if (thr->engine->batch != 0) {
+ if (engine->batch != 0) {
if (c->socket.closed || c->socket.error != 0) {
- wq = &thr->engine->close_work_queue;
+ wq = &engine->close_work_queue;
handler = nxt_event_conn_close_socket;
} else {
- wq = &thr->engine->shutdown_work_queue;
+ wq = &engine->shutdown_work_queue;
handler = nxt_event_conn_shutdown_socket;
}
- nxt_thread_work_queue_add(thr, wq, handler,
- (void *) (uintptr_t) c->socket.fd, NULL,
- &nxt_main_log);
+ nxt_thread_work_queue_add(thr, wq, handler, task,
+ (void *) (uintptr_t) c->socket.fd, NULL);
} else {
nxt_socket_close(c->socket.fd);
@@ -170,7 +180,7 @@ nxt_event_conn_close(nxt_thread_t *thr, nxt_event_conn_t *c)
static void
-nxt_event_conn_shutdown_socket(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_shutdown_socket(nxt_task_t *task, void *obj, void *data)
{
nxt_socket_t s;
@@ -178,14 +188,15 @@ nxt_event_conn_shutdown_socket(nxt_thread_t *thr, void *obj, void *data)
nxt_socket_shutdown(s, SHUT_RDWR);
- nxt_thread_work_queue_add(thr, &thr->engine->close_work_queue,
- nxt_event_conn_close_socket,
- (void *) (uintptr_t) s, NULL, &nxt_main_log);
+ nxt_thread_work_queue_add(task->thread,
+ &task->thread->engine->close_work_queue,
+ nxt_event_conn_close_socket, task,
+ (void *) (uintptr_t) s, NULL);
}
static void
-nxt_event_conn_close_socket(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_close_socket(nxt_task_t *task, void *obj, void *data)
{
nxt_socket_t s;
diff --git a/src/nxt_event_conn.h b/src/nxt_event_conn.h
index fe7d794a..c35dcf42 100644
--- a/src/nxt_event_conn.h
+++ b/src/nxt_event_conn.h
@@ -45,11 +45,8 @@ typedef struct {
typedef struct {
- void (*connect)(nxt_thread_t *thr, void *obj,
- void *data);
-
- void (*accept)(nxt_thread_t *thr, void *obj,
- void *data);
+ nxt_work_handler_t connect;
+ nxt_work_handler_t accept;
/*
* The read() with NULL c->read buffer waits readiness of a connection
@@ -59,8 +56,7 @@ typedef struct {
* connection without errors. In the latter case state's close_handler
* is called.
*/
- void (*read)(nxt_thread_t *thr, void *obj,
- void *data);
+ nxt_work_handler_t read;
ssize_t (*recvbuf)(nxt_event_conn_t *c, nxt_buf_t *b);
@@ -71,8 +67,7 @@ typedef struct {
* The write() is an interface to write a buffer chain with a given rate
* limit. It calls write_chunk() in a cycle and handles write event timer.
*/
- void (*write)(nxt_thread_t *thr, void *obj,
- void *data);
+ nxt_work_handler_t write;
/*
* The write_chunk() interface writes a buffer chain with a given limit
@@ -80,9 +75,8 @@ typedef struct {
* buffers data and calls the library specific send() interface to write
* the buffered data eventually.
*/
- ssize_t (*write_chunk)(nxt_thread_t *thr,
- nxt_event_conn_t *c, nxt_buf_t *b,
- size_t limit);
+ ssize_t (*write_chunk)(nxt_event_conn_t *c,
+ nxt_buf_t *b, size_t limit);
/*
* The sendbuf() is an interface for OS-specific sendfile
@@ -102,8 +96,7 @@ typedef struct {
ssize_t (*send)(nxt_event_conn_t *c, void *buf,
size_t size);
- void (*shutdown)(nxt_thread_t *thr, void *obj,
- void *data);
+ nxt_work_handler_t shutdown;
} nxt_event_conn_io_t;
@@ -147,6 +140,7 @@ struct nxt_event_conn_s {
nxt_mem_pool_t *mem_pool;
+ nxt_task_t task;
nxt_log_t log;
nxt_listen_socket_t *listen;
@@ -178,12 +172,13 @@ typedef struct {
/* Must be the first field. */
nxt_event_fd_t socket;
+ nxt_task_t task;
+
uint32_t ready;
uint32_t batch;
/* An accept() interface is cached to minimize memory accesses. */
- void (*accept)(nxt_thread_t *thr, void *obj,
- void *data);
+ nxt_work_handler_t accept;
nxt_listen_socket_t *listen;
@@ -194,13 +189,13 @@ typedef struct {
#define \
-nxt_event_conn_io_handle(thr, wq, handler, c, data) \
+nxt_event_conn_io_handle(thr, wq, handler, task, c, data) \
do { \
if (thr->engine->batch != 0) { \
- nxt_thread_work_queue_add(thr, wq, handler, c, data, thr->log); \
+ nxt_thread_work_queue_add(thr, wq, handler, task, c, data); \
\
} else { \
- handler(thr, c, data); \
+ handler(task, c, data); \
} \
} while (0)
@@ -259,9 +254,8 @@ nxt_event_conn_tcp_nodelay_on(c) \
NXT_EXPORT nxt_event_conn_t *nxt_event_conn_create(nxt_mem_pool_t *mp,
nxt_log_t *log);
-void nxt_event_conn_io_shutdown(nxt_thread_t *thr, void *obj,
- void *data);
-NXT_EXPORT void nxt_event_conn_close(nxt_thread_t *thr, nxt_event_conn_t *c);
+void nxt_event_conn_io_shutdown(nxt_task_t *task, void *obj, void *data);
+NXT_EXPORT void nxt_event_conn_close(nxt_task_t *task, nxt_event_conn_t *c);
NXT_EXPORT void nxt_event_conn_timer(nxt_event_engine_t *engine,
nxt_event_conn_t *c, const nxt_event_conn_state_t *state,
@@ -269,77 +263,66 @@ NXT_EXPORT void nxt_event_conn_timer(nxt_event_engine_t *engine,
NXT_EXPORT void nxt_event_conn_work_queue_set(nxt_event_conn_t *c,
nxt_work_queue_t *wq);
-NXT_EXPORT void nxt_event_conn_connect(nxt_thread_t *thr, nxt_event_conn_t *c);
-void nxt_event_conn_batch_socket(nxt_thread_t *thr, void *obj,
- void *data);
-void nxt_event_conn_io_connect(nxt_thread_t *thr, void *obj,
- void *data);
-nxt_int_t nxt_event_conn_socket(nxt_thread_t *thr,
- nxt_event_conn_t *c);
-void nxt_event_conn_connect_test(nxt_thread_t *thr, void *obj,
- void *data);
-void nxt_event_conn_connect_error(nxt_thread_t *thr, void *obj,
- void *data);
+NXT_EXPORT void nxt_event_conn_connect(nxt_task_t *task, nxt_event_conn_t *c);
+void nxt_event_conn_batch_socket(nxt_task_t *task, void *obj, void *data);
+void nxt_event_conn_io_connect(nxt_task_t *task, void *obj, void *data);
+nxt_int_t nxt_event_conn_socket(nxt_task_t *task, nxt_event_conn_t *c);
+void nxt_event_conn_connect_test(nxt_task_t *task, void *obj, void *data);
+void nxt_event_conn_connect_error(nxt_task_t *task, void *obj, void *data);
-NXT_EXPORT nxt_int_t nxt_event_conn_listen(nxt_thread_t *thr,
+NXT_EXPORT nxt_int_t nxt_event_conn_listen(nxt_task_t *task,
nxt_listen_socket_t *ls);
-void nxt_event_conn_io_accept(nxt_thread_t *thr, void *obj,
- void *data);
-NXT_EXPORT void nxt_event_conn_accept(nxt_thread_t *thr,
+void nxt_event_conn_io_accept(nxt_task_t *task, void *obj, void *data);
+NXT_EXPORT void nxt_event_conn_accept(nxt_task_t *task,
nxt_event_conn_listen_t *cls, nxt_event_conn_t *c);
-void nxt_event_conn_accept_error(nxt_thread_t *thr,
- nxt_event_conn_listen_t *cls, const char *accept_syscall, nxt_err_t err);
+void nxt_event_conn_accept_error(nxt_task_t *task, nxt_event_conn_listen_t *cls,
+ const char *accept_syscall, nxt_err_t err);
-NXT_EXPORT void nxt_event_conn_read(nxt_thread_t *thr, nxt_event_conn_t *c);
-void nxt_event_conn_io_read(nxt_thread_t *thr, void *obj,
- void *data);
+NXT_EXPORT void nxt_event_conn_read(nxt_task_t *task, nxt_event_conn_t *c);
+void nxt_event_conn_io_read(nxt_task_t *task, void *obj, void *data);
ssize_t nxt_event_conn_io_recvbuf(nxt_event_conn_t *c, nxt_buf_t *b);
ssize_t nxt_event_conn_io_recv(nxt_event_conn_t *c, void *buf,
size_t size, nxt_uint_t flags);
-NXT_EXPORT void nxt_event_conn_write(nxt_thread_t *thr, nxt_event_conn_t *c);
+NXT_EXPORT void nxt_event_conn_write(nxt_task_t *task, nxt_event_conn_t *c);
size_t nxt_event_conn_write_limit(nxt_event_conn_t *c);
nxt_bool_t nxt_event_conn_write_delayed(nxt_event_engine_t *engine,
nxt_event_conn_t *c, size_t sent);
-void nxt_event_conn_io_write(nxt_thread_t *thr, void *obj,
- void *data);
-ssize_t nxt_event_conn_io_write_chunk(nxt_thread_t *thr,
- nxt_event_conn_t *c, nxt_buf_t *b, size_t limit);
-ssize_t nxt_event_conn_io_writev(nxt_event_conn_t *c,
- nxt_iobuf_t *iob, nxt_uint_t niob);
-ssize_t nxt_event_conn_io_send(nxt_event_conn_t *c, void *buf,
- size_t size);
-
-NXT_EXPORT void nxt_event_conn_job_sendfile(nxt_thread_t *thr,
+void nxt_event_conn_io_write(nxt_task_t *task, void *obj, void *data);
+ssize_t nxt_event_conn_io_write_chunk(nxt_event_conn_t *c, nxt_buf_t *b,
+ size_t limit);
+ssize_t nxt_event_conn_io_writev(nxt_event_conn_t *c, nxt_iobuf_t *iob,
+ nxt_uint_t niob);
+ssize_t nxt_event_conn_io_send(nxt_event_conn_t *c, void *buf, size_t size);
+
+NXT_EXPORT void nxt_event_conn_job_sendfile(nxt_task_t *task,
nxt_event_conn_t *c);
#define \
-nxt_event_conn_connect_enqueue(thr, c) \
+nxt_event_conn_connect_enqueue(thr, task, c) \
nxt_thread_work_queue_add(thr, &thr->engine->socket_work_queue, \
nxt_event_conn_batch_socket, \
- c, c->socket.data, c->socket.log)
+ task, c, c->socket.data)
#define \
-nxt_event_conn_read_enqueue(thr, c) \
+nxt_event_conn_read_enqueue(thr, task, c) \
do { \
c->socket.read_work_queue = &thr->engine->read_work_queue; \
\
nxt_thread_work_queue_add(thr, &thr->engine->read_work_queue, \
- c->io->read, c, c->socket.data, \
- c->socket.log); \
+ c->io->read, task, c, c->socket.data); \
} while (0)
#define \
-nxt_event_conn_write_enqueue(thr, c) \
+nxt_event_conn_write_enqueue(thr, task, c) \
do { \
c->socket.write_work_queue = &thr->engine->write_work_queue; \
\
nxt_thread_work_queue_add(thr, &thr->engine->write_work_queue, \
- c->io->write, c, c->socket.data, \
- c->socket.log); \
+ c->io->write, task, c, c->socket.data); \
} while (0)
@@ -376,7 +359,8 @@ typedef struct {
NXT_EXPORT nxt_event_conn_proxy_t *nxt_event_conn_proxy_create(
nxt_event_conn_t *c);
-NXT_EXPORT void nxt_event_conn_proxy(nxt_event_conn_proxy_t *p);
+NXT_EXPORT void nxt_event_conn_proxy(nxt_task_t *task,
+ nxt_event_conn_proxy_t *p);
#endif /* _NXT_EVENT_CONN_H_INCLUDED_ */
diff --git a/src/nxt_event_conn_accept.c b/src/nxt_event_conn_accept.c
index ef0eea2c..a1339235 100644
--- a/src/nxt_event_conn_accept.c
+++ b/src/nxt_event_conn_accept.c
@@ -18,23 +18,24 @@
*/
-static nxt_event_conn_t *nxt_event_conn_accept_alloc(nxt_thread_t *thr,
+static nxt_event_conn_t *nxt_event_conn_accept_alloc(nxt_task_t *task,
nxt_event_conn_listen_t *cls);
-static void nxt_event_conn_listen_handler(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_listen_handler(nxt_task_t *task, void *obj,
void *data);
-static nxt_event_conn_t *nxt_event_conn_accept_next(nxt_thread_t *thr,
+static nxt_event_conn_t *nxt_event_conn_accept_next(nxt_task_t *task,
nxt_event_conn_listen_t *cls);
-static nxt_int_t nxt_event_conn_accept_close_idle(nxt_thread_t *thr,
+static nxt_int_t nxt_event_conn_accept_close_idle(nxt_task_t *task,
nxt_event_conn_listen_t *cls);
-static void nxt_event_conn_listen_event_error(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_listen_event_error(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_listen_timer_handler(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_listen_timer_handler(nxt_task_t *task, void *obj,
void *data);
nxt_int_t
-nxt_event_conn_listen(nxt_thread_t *thr, nxt_listen_socket_t *ls)
+nxt_event_conn_listen(nxt_task_t *task, nxt_listen_socket_t *ls)
{
+ nxt_event_engine_t *engine;
nxt_event_conn_listen_t *cls;
cls = nxt_zalloc(sizeof(nxt_event_conn_listen_t));
@@ -42,13 +43,14 @@ nxt_event_conn_listen(nxt_thread_t *thr, nxt_listen_socket_t *ls)
if (nxt_fast_path(cls != NULL)) {
cls->socket.fd = ls->socket;
- cls->batch = thr->engine->batch;
+ engine = task->thread->engine;
+ cls->batch = engine->batch;
if (cls->batch != 0) {
- cls->socket.read_work_queue = &thr->engine->accept_work_queue;
+ cls->socket.read_work_queue = &engine->accept_work_queue;
} else {
- cls->socket.read_work_queue = &thr->work_queue.main;
+ cls->socket.read_work_queue = &task->thread->work_queue.main;
cls->batch = 1;
}
@@ -56,20 +58,26 @@ nxt_event_conn_listen(nxt_thread_t *thr, nxt_listen_socket_t *ls)
cls->socket.error_handler = nxt_event_conn_listen_event_error;
cls->socket.log = &nxt_main_log;
- cls->accept = thr->engine->event->io->accept;
+ cls->accept = engine->event->io->accept;
cls->listen = ls;
- cls->timer.work_queue = &thr->work_queue.main;
+ cls->timer.work_queue = &task->thread->work_queue.main;
cls->timer.handler = nxt_event_conn_listen_timer_handler;
cls->timer.log = &nxt_main_log;
nxt_event_timer_ident(&cls->timer, cls->socket.fd);
- if (nxt_event_conn_accept_alloc(thr, cls) != NULL) {
- nxt_event_fd_enable_accept(thr->engine, &cls->socket);
+ cls->task.thread = task->thread;
+ cls->task.log = &nxt_main_log;
+ cls->task.ident = nxt_task_next_ident();
+ cls->socket.task = &cls->task;
+ cls->timer.task = &cls->task;
- nxt_queue_insert_head(&thr->engine->listen_connections, &cls->link);
+ if (nxt_event_conn_accept_alloc(task, cls) != NULL) {
+ nxt_event_fd_enable_accept(engine, &cls->socket);
+
+ nxt_queue_insert_head(&engine->listen_connections, &cls->link);
}
return NXT_OK;
@@ -80,14 +88,17 @@ nxt_event_conn_listen(nxt_thread_t *thr, nxt_listen_socket_t *ls)
static nxt_event_conn_t *
-nxt_event_conn_accept_alloc(nxt_thread_t *thr, nxt_event_conn_listen_t *cls)
+nxt_event_conn_accept_alloc(nxt_task_t *task, nxt_event_conn_listen_t *cls)
{
nxt_sockaddr_t *sa, *remote;
nxt_mem_pool_t *mp;
nxt_event_conn_t *c;
+ nxt_event_engine_t *engine;
nxt_listen_socket_t *ls;
- if (thr->engine->connections < thr->engine->max_connections) {
+ engine = task->thread->engine;
+
+ if (engine->connections < engine->max_connections) {
mp = nxt_mem_pool_create(cls->listen->mem_pool_size);
@@ -123,19 +134,19 @@ nxt_event_conn_accept_alloc(nxt_thread_t *thr, nxt_event_conn_listen_t *cls)
static void
-nxt_event_conn_listen_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_listen_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_listen_t *cls;
cls = obj;
cls->ready = cls->batch;
- cls->accept(thr, cls, data);
+ cls->accept(task, cls, data);
}
void
-nxt_event_conn_io_accept(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_io_accept(nxt_task_t *task, void *obj, void *data)
{
socklen_t len;
nxt_socket_t s;
@@ -162,7 +173,7 @@ nxt_event_conn_io_accept(nxt_thread_t *thr, void *obj, void *data)
s = accept(cls->socket.fd, sa, &len);
if (s == -1) {
- nxt_event_conn_accept_error(thr, cls, "accept", nxt_socket_errno);
+ nxt_event_conn_accept_error(task, cls, "accept", nxt_socket_errno);
return;
}
@@ -179,14 +190,14 @@ nxt_event_conn_io_accept(nxt_thread_t *thr, void *obj, void *data)
#endif
- nxt_log_debug(thr->log, "accept(%d): %d", cls->socket.fd, s);
+ nxt_debug(task, "accept(%d): %d", cls->socket.fd, s);
- nxt_event_conn_accept(thr, cls, c);
+ nxt_event_conn_accept(task, cls, c);
}
void
-nxt_event_conn_accept(nxt_thread_t *thr, nxt_event_conn_listen_t *cls,
+nxt_event_conn_accept(nxt_task_t *task, nxt_event_conn_listen_t *cls,
nxt_event_conn_t *c)
{
nxt_event_conn_t *next;
@@ -197,10 +208,9 @@ nxt_event_conn_accept(nxt_thread_t *thr, nxt_event_conn_listen_t *cls,
/* This allocation cannot fail. */
(void) nxt_sockaddr_text(c->mem_pool, c->remote, 0);
- nxt_log_debug(c->socket.log, "client: %*s",
- c->remote->text_len, c->remote->text);
+ nxt_debug(task, "client: %*s", c->remote->text_len, c->remote->text);
- nxt_queue_insert_head(&thr->engine->idle_connections, &c->link);
+ nxt_queue_insert_head(&task->thread->engine->idle_connections, &c->link);
c->read_work_queue = c->listen->work_queue;
c->write_work_queue = c->listen->work_queue;
@@ -208,41 +218,39 @@ nxt_event_conn_accept(nxt_thread_t *thr, nxt_event_conn_listen_t *cls,
if (c->listen->read_after_accept) {
//c->socket.read_ready = 1;
- thr->log = c->socket.log;
- c->listen->handler(thr, c, NULL);
- thr->log = cls->socket.log;
+ c->listen->handler(task, c, NULL);
} else {
- nxt_thread_work_queue_add(thr, c->write_work_queue,
- c->listen->handler, c, NULL, c->socket.log);
+ nxt_thread_work_queue_add(task->thread, c->write_work_queue,
+ c->listen->handler, task, c, NULL);
}
- next = nxt_event_conn_accept_next(thr, cls);
+ next = nxt_event_conn_accept_next(task, cls);
if (next != NULL && cls->socket.read_ready) {
- nxt_thread_work_queue_add(thr, cls->socket.read_work_queue,
- cls->accept, cls, next, cls->socket.log);
+ nxt_thread_work_queue_add(task->thread, cls->socket.read_work_queue,
+ cls->accept, task, cls, next);
}
}
static nxt_event_conn_t *
-nxt_event_conn_accept_next(nxt_thread_t *thr, nxt_event_conn_listen_t *cls)
+nxt_event_conn_accept_next(nxt_task_t *task, nxt_event_conn_listen_t *cls)
{
nxt_event_conn_t *c;
cls->socket.data = NULL;
do {
- c = nxt_event_conn_accept_alloc(thr, cls);
+ c = nxt_event_conn_accept_alloc(task, cls);
if (nxt_fast_path(c != NULL)) {
return c;
}
- } while (nxt_event_conn_accept_close_idle(thr, cls) == NXT_OK);
+ } while (nxt_event_conn_accept_close_idle(task, cls) == NXT_OK);
- nxt_log_alert(cls->socket.log, "no available connections, "
+ nxt_log(task, NXT_LOG_CRIT, "no available connections, "
"new connections are not accepted within 1s");
return NULL;
@@ -250,8 +258,7 @@ nxt_event_conn_accept_next(nxt_thread_t *thr, nxt_event_conn_listen_t *cls)
static nxt_int_t
-nxt_event_conn_accept_close_idle(nxt_thread_t *thr,
- nxt_event_conn_listen_t *cls)
+nxt_event_conn_accept_close_idle(nxt_task_t *task, nxt_event_conn_listen_t *cls)
{
nxt_queue_t *idle;
nxt_queue_link_t *link;
@@ -261,7 +268,7 @@ nxt_event_conn_accept_close_idle(nxt_thread_t *thr,
NXT_LOG_INFO, 2, "idle connections closed", NXT_LOG_MODERATION
};
- idle = &thr->engine->idle_connections;
+ idle = &task->thread->engine->idle_connections;
for (link = nxt_queue_last(idle);
link != nxt_queue_head(idle);
@@ -271,24 +278,25 @@ nxt_event_conn_accept_close_idle(nxt_thread_t *thr,
if (!c->socket.read_ready) {
nxt_log_moderate(&nxt_idle_close_log_moderation, NXT_LOG_INFO,
- thr->log, "no available connections, "
+ task->log, "no available connections, "
"close idle connection");
nxt_queue_remove(link);
- nxt_event_conn_close(thr, c);
+ nxt_event_conn_close(task, c);
return NXT_OK;
}
}
- nxt_event_timer_add(thr->engine, &cls->timer, 1000);
- nxt_event_fd_disable_read(thr->engine, &cls->socket);
+ nxt_event_timer_add(task->thread->engine, &cls->timer, 1000);
+
+ nxt_event_fd_disable_read(task->thread->engine, &cls->socket);
return NXT_DECLINED;
}
void
-nxt_event_conn_accept_error(nxt_thread_t *thr, nxt_event_conn_listen_t *cls,
+nxt_event_conn_accept_error(nxt_task_t *task, nxt_event_conn_listen_t *cls,
const char *accept_syscall, nxt_err_t err)
{
static nxt_log_moderation_t nxt_accept_log_moderation = {
@@ -300,13 +308,12 @@ nxt_event_conn_accept_error(nxt_thread_t *thr, nxt_event_conn_listen_t *cls,
switch (err) {
case NXT_EAGAIN:
- nxt_log_debug(thr->log, "%s(%d) %E",
- accept_syscall, cls->socket.fd, err);
+ nxt_debug(task, "%s(%d) %E", accept_syscall, cls->socket.fd, err);
return;
case ECONNABORTED:
- nxt_log_moderate(&nxt_accept_log_moderation, NXT_LOG_INFO,
- thr->log, "%s(%d) failed %E",
+ nxt_log_moderate(&nxt_accept_log_moderation, NXT_LOG_WARN,
+ task->log, "%s(%d) failed %E",
accept_syscall, cls->socket.fd, err);
return;
@@ -314,24 +321,24 @@ nxt_event_conn_accept_error(nxt_thread_t *thr, nxt_event_conn_listen_t *cls,
case ENFILE:
case ENOBUFS:
case ENOMEM:
- if (nxt_event_conn_accept_close_idle(thr, cls) != NXT_OK) {
- nxt_log_alert(thr->log, "%s(%d) failed %E, "
- "new connections are not accepted within 1s",
- accept_syscall, cls->socket.fd, err);
+ if (nxt_event_conn_accept_close_idle(task, cls) != NXT_OK) {
+ nxt_log(task, NXT_LOG_CRIT, "%s(%d) failed %E, "
+ "new connections are not accepted within 1s",
+ accept_syscall, cls->socket.fd, err);
}
return;
default:
- nxt_log_alert(thr->log, "%s(%d) failed %E",
- accept_syscall, cls->socket.fd, err);
+ nxt_log(task, NXT_LOG_CRIT, "%s(%d) failed %E",
+ accept_syscall, cls->socket.fd, err);
return;
}
}
static void
-nxt_event_conn_listen_timer_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_listen_timer_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_event_timer_t *ev;
@@ -343,25 +350,25 @@ nxt_event_conn_listen_timer_handler(nxt_thread_t *thr, void *obj, void *data)
c = cls->socket.data;
if (c == NULL) {
- c = nxt_event_conn_accept_next(thr, cls);
+ c = nxt_event_conn_accept_next(task, cls);
if (c == NULL) {
return;
}
}
- nxt_event_fd_enable_accept(thr->engine, &cls->socket);
+ nxt_event_fd_enable_accept(task->thread->engine, &cls->socket);
- cls->accept(thr, cls, c);
+ cls->accept(task, cls, c);
}
static void
-nxt_event_conn_listen_event_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_listen_event_error(nxt_task_t *task, void *obj, void *data)
{
nxt_event_fd_t *ev;
ev = obj;
- nxt_log_alert(thr->log, "accept(%d) event error", ev->fd);
+ nxt_log(task, NXT_LOG_CRIT, "accept(%d) event error", ev->fd);
}
diff --git a/src/nxt_event_conn_connect.c b/src/nxt_event_conn_connect.c
index f614dcda..55554720 100644
--- a/src/nxt_event_conn_connect.c
+++ b/src/nxt_event_conn_connect.c
@@ -8,37 +8,38 @@
void
-nxt_event_conn_connect(nxt_thread_t *thr, nxt_event_conn_t *c)
+nxt_event_conn_connect(nxt_task_t *task, nxt_event_conn_t *c)
{
- void *data;
+ void *data;
+ nxt_event_engine_t *engine;
data = c->socket.data;
+ engine = task->thread->engine;
- if (thr->engine->batch != 0) {
- nxt_thread_work_queue_add(thr, &thr->engine->socket_work_queue,
- nxt_event_conn_batch_socket, c, data,
- c->socket.log);
+ if (engine->batch != 0) {
+ nxt_thread_work_queue_add(task->thread, &engine->socket_work_queue,
+ nxt_event_conn_batch_socket, task, c, data);
return;
}
- if (nxt_event_conn_socket(thr, c) == NXT_OK) {
- c->io->connect(thr, c, data);
+ if (nxt_event_conn_socket(task, c) == NXT_OK) {
+ c->io->connect(task, c, data);
return;
}
- c->write_state->error_handler(thr, c, data);
+ c->write_state->error_handler(task, c, data);
}
void
-nxt_event_conn_batch_socket(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_batch_socket(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_work_handler_t handler;
c = obj;
- if (nxt_event_conn_socket(thr, c) == NXT_OK) {
+ if (nxt_event_conn_socket(task, c) == NXT_OK) {
c->socket.write_work_queue = c->write_work_queue;
handler = c->io->connect;
@@ -46,16 +47,18 @@ nxt_event_conn_batch_socket(nxt_thread_t *thr, void *obj, void *data)
handler = c->write_state->error_handler;
}
- nxt_thread_work_queue_add(thr, &thr->engine->connect_work_queue,
- handler, c, data, thr->log);
+ nxt_thread_work_queue_add(task->thread,
+ &task->thread->engine->connect_work_queue,
+ handler, task, c, data);
}
void
-nxt_event_conn_io_connect(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_io_connect(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_work_handler_t handler;
+ nxt_event_engine_t *engine;
const nxt_event_conn_state_t *state;
c = obj;
@@ -73,9 +76,11 @@ nxt_event_conn_io_connect(nxt_thread_t *thr, void *obj, void *data)
c->socket.write_handler = nxt_event_conn_connect_test;
c->socket.error_handler = state->error_handler;
- nxt_event_conn_timer(thr->engine, c, state, &c->write_timer);
+ engine = task->thread->engine;
- nxt_event_fd_enable_write(thr->engine, &c->socket);
+ nxt_event_conn_timer(engine, c, state, &c->write_timer);
+
+ nxt_event_fd_enable_write(engine, &c->socket);
return;
case NXT_DECLINED:
@@ -87,17 +92,18 @@ nxt_event_conn_io_connect(nxt_thread_t *thr, void *obj, void *data)
break;
}
- nxt_event_conn_io_handle(thr, c->write_work_queue, handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue, handler, task,
+ c, data);
}
nxt_int_t
-nxt_event_conn_socket(nxt_thread_t *thr, nxt_event_conn_t *c)
+nxt_event_conn_socket(nxt_task_t *task, nxt_event_conn_t *c)
{
nxt_uint_t family;
nxt_socket_t s;
- nxt_log_debug(thr->log, "event conn socket");
+ nxt_debug(task, "event conn socket");
family = c->remote->u.sockaddr.sa_family;
@@ -122,6 +128,10 @@ nxt_event_conn_socket(nxt_thread_t *thr, nxt_event_conn_t *c)
nxt_event_timer_ident(&c->read_timer, s);
nxt_event_timer_ident(&c->write_timer, s);
+ c->socket.task = task;
+ c->read_timer.task = task;
+ c->write_timer.task = task;
+
if (c->local != NULL) {
if (nxt_slow_path(nxt_socket_bind(s, c->local, 0) != NXT_OK)) {
nxt_socket_close(s);
@@ -134,7 +144,7 @@ nxt_event_conn_socket(nxt_thread_t *thr, nxt_event_conn_t *c)
void
-nxt_event_conn_connect_test(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_connect_test(nxt_task_t *task, void *obj, void *data)
{
int ret, err;
socklen_t len;
@@ -142,9 +152,9 @@ nxt_event_conn_connect_test(nxt_thread_t *thr, void *obj, void *data)
c = obj;
- nxt_log_debug(thr->log, "event connect test fd:%d", c->socket.fd);
+ nxt_debug(task, "event connect test fd:%d", c->socket.fd);
- nxt_event_fd_block_write(thr->engine, &c->socket);
+ nxt_event_fd_block_write(task->thread->engine, &c->socket);
if (c->write_state->autoreset_timer) {
nxt_event_timer_disable(&c->write_timer);
@@ -165,23 +175,23 @@ nxt_event_conn_connect_test(nxt_thread_t *thr, void *obj, void *data)
}
if (err == 0) {
- nxt_event_conn_io_handle(thr, c->write_work_queue,
- c->write_state->ready_handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue,
+ c->write_state->ready_handler, task, c, data);
return;
}
c->socket.error = err;
- nxt_log_error(nxt_socket_error_level(err, c->socket.log_error), thr->log,
- "connect(%d, %*s) failed %E",
- c->socket.fd, c->remote->text_len, c->remote->text, err);
+ nxt_log(task, nxt_socket_error_level(err, c->socket.log_error),
+ "connect(%d, %*s) failed %E",
+ c->socket.fd, c->remote->text_len, c->remote->text, err);
- nxt_event_conn_connect_error(thr, c, data);
+ nxt_event_conn_connect_error(task, c, data);
}
void
-nxt_event_conn_connect_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_connect_error(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_work_handler_t handler;
@@ -209,5 +219,6 @@ nxt_event_conn_connect_error(nxt_thread_t *thr, void *obj, void *data)
break;
}
- nxt_event_conn_io_handle(thr, c->write_work_queue, handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue, handler,
+ task, c, data);
}
diff --git a/src/nxt_event_conn_job_sendfile.c b/src/nxt_event_conn_job_sendfile.c
index 140febab..86a05969 100644
--- a/src/nxt_event_conn_job_sendfile.c
+++ b/src/nxt_event_conn_job_sendfile.c
@@ -18,28 +18,28 @@ typedef struct {
} nxt_job_sendfile_t;
-static void nxt_event_conn_job_sendfile_start(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_job_sendfile_start(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_job_sendfile_handler(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_job_sendfile_handler(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_job_sendfile_return(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_job_sendfile_return(nxt_task_t *task, void *obj,
void *data);
-static nxt_buf_t *nxt_event_conn_job_sendfile_completion(nxt_thread_t *thr,
+static nxt_buf_t *nxt_event_conn_job_sendfile_completion(nxt_task_t *task,
nxt_event_conn_t *c, nxt_buf_t *b);
void
-nxt_event_conn_job_sendfile(nxt_thread_t *thr, nxt_event_conn_t *c)
+nxt_event_conn_job_sendfile(nxt_task_t *task, nxt_event_conn_t *c)
{
- nxt_event_fd_disable(thr->engine, &c->socket);
+ nxt_event_fd_disable(task->thread->engine, &c->socket);
/* A work item data is not used in nxt_event_conn_job_sendfile_start(). */
- nxt_event_conn_job_sendfile_start(thr, c, NULL);
+ nxt_event_conn_job_sendfile_start(task, c, NULL);
}
static void
-nxt_event_conn_job_sendfile_start(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_job_sendfile_start(nxt_task_t *task, void *obj, void *data)
{
nxt_iobuf_t b;
nxt_event_conn_t *c;
@@ -48,12 +48,12 @@ nxt_event_conn_job_sendfile_start(nxt_thread_t *thr, void *obj, void *data)
c = obj;
- nxt_log_debug(thr->log, "event conn sendfile fd:%d", c->socket.fd);
+ nxt_debug(task, "event conn sendfile fd:%d", c->socket.fd);
jbs = nxt_job_create(c->mem_pool, sizeof(nxt_job_sendfile_t));
if (nxt_slow_path(jbs == NULL)) {
- c->write_state->error_handler(thr, c, NULL);
+ c->write_state->error_handler(task, c, NULL);
return;
}
@@ -74,7 +74,7 @@ nxt_event_conn_job_sendfile_start(nxt_thread_t *thr, void *obj, void *data)
sb.size = 0;
sb.limit = jbs->limit;
- if (nxt_sendbuf_mem_coalesce(&sb) != 0 || !sb.sync) {
+ if (nxt_sendbuf_mem_coalesce(c->socket.task, &sb) != 0 || !sb.sync) {
jbs->job.thread_pool = c->u.thread_pool;
jbs->job.log = c->socket.log;
@@ -88,17 +88,17 @@ nxt_event_conn_job_sendfile_start(nxt_thread_t *thr, void *obj, void *data)
c->write_timer.state = NXT_EVENT_TIMER_BLOCKED;
}
- nxt_job_start(thr, &jbs->job, nxt_event_conn_job_sendfile_handler);
+ nxt_job_start(task, &jbs->job, nxt_event_conn_job_sendfile_handler);
return;
}
}
- nxt_event_conn_job_sendfile_return(thr, jbs, c);
+ nxt_event_conn_job_sendfile_return(task, jbs, c);
}
static void
-nxt_event_conn_job_sendfile_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_job_sendfile_handler(nxt_task_t *task, void *obj, void *data)
{
ssize_t ret;
nxt_buf_t *b;
@@ -109,7 +109,7 @@ nxt_event_conn_job_sendfile_handler(nxt_thread_t *thr, void *obj, void *data)
jbs = obj;
c = data;
- nxt_log_debug(thr->log, "event conn job sendfile fd:%d", c->socket.fd);
+ nxt_debug(task, "event conn job sendfile fd:%d", c->socket.fd);
first = c->socket.write_ready;
b = jbs->out;
@@ -146,24 +146,25 @@ nxt_event_conn_job_sendfile_handler(nxt_thread_t *thr, void *obj, void *data)
} while (c->socket.write_ready);
- if (first && thr->thread_pool->work_queue.head != NULL) {
+ if (first && task->thread->thread_pool->work_queue.head != NULL) {
goto fast;
}
done:
- nxt_job_return(thr, &jbs->job, jbs->ready_handler);
+ nxt_job_return(task, &jbs->job, jbs->ready_handler);
return;
fast:
- nxt_thread_pool_post(thr->thread_pool, nxt_event_conn_job_sendfile_handler,
- jbs, c, thr->log);
+ nxt_thread_pool_post(task->thread->thread_pool,
+ nxt_event_conn_job_sendfile_handler,
+ &jbs->job.task, jbs, c);
}
static void
-nxt_event_conn_job_sendfile_return(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_job_sendfile_return(nxt_task_t *task, void *obj, void *data)
{
size_t sent;
nxt_buf_t *b;
@@ -179,7 +180,7 @@ nxt_event_conn_job_sendfile_return(nxt_thread_t *thr, void *obj, void *data)
sent = jbs->sent;
c->sent += sent;
- nxt_log_debug(thr->log, "event conn sendfile sent:%z", sent);
+ nxt_debug(task, "event conn sendfile sent:%z", sent);
b = jbs->out;
@@ -187,7 +188,7 @@ nxt_event_conn_job_sendfile_return(nxt_thread_t *thr, void *obj, void *data)
nxt_job_destroy(jbs);
if (c->write_state->process_buffers) {
- b = nxt_event_conn_job_sendfile_completion(thr, c, b);
+ b = nxt_event_conn_job_sendfile_completion(task, c, b);
done = (b == NULL);
@@ -200,7 +201,7 @@ nxt_event_conn_job_sendfile_return(nxt_thread_t *thr, void *obj, void *data)
if (b != NULL) {
/* But new data has been added. */
- nxt_event_conn_job_sendfile_start(thr, c, NULL);
+ nxt_event_conn_job_sendfile_start(task, c, NULL);
}
return;
@@ -215,17 +216,18 @@ nxt_event_conn_job_sendfile_return(nxt_thread_t *thr, void *obj, void *data)
}
if (c->socket.error == 0
- && !nxt_event_conn_write_delayed(thr->engine, c, sent))
+ && !nxt_event_conn_write_delayed(task->thread->engine, c, sent))
{
- nxt_event_conn_timer(thr->engine, c, c->write_state, &c->write_timer);
+ nxt_event_conn_timer(task->thread->engine, c, c->write_state,
+ &c->write_timer);
- nxt_event_fd_oneshot_write(thr->engine, &c->socket);
+ nxt_event_fd_oneshot_write(task->thread->engine, &c->socket);
}
if (sent != 0) {
- nxt_event_conn_io_handle(thr, c->write_work_queue,
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue,
c->write_state->ready_handler,
- c, c->socket.data);
+ task, c, c->socket.data);
/*
* Fall through if first operations were
* successful but the last one failed.
@@ -233,15 +235,15 @@ nxt_event_conn_job_sendfile_return(nxt_thread_t *thr, void *obj, void *data)
}
if (nxt_slow_path(c->socket.error != 0)) {
- nxt_event_conn_io_handle(thr, c->write_work_queue,
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue,
c->write_state->error_handler,
- c, c->socket.data);
+ task, c, c->socket.data);
}
}
static nxt_buf_t *
-nxt_event_conn_job_sendfile_completion(nxt_thread_t *thr, nxt_event_conn_t *c,
+nxt_event_conn_job_sendfile_completion(nxt_task_t *task, nxt_event_conn_t *c,
nxt_buf_t *b)
{
while (b != NULL) {
@@ -255,9 +257,8 @@ nxt_event_conn_job_sendfile_completion(nxt_thread_t *thr, nxt_event_conn_t *c,
break;
}
- nxt_thread_work_queue_add(thr, c->write_work_queue,
- b->completion_handler,
- b, b->parent, thr->log);
+ nxt_thread_work_queue_add(task->thread, c->write_work_queue,
+ b->completion_handler, task, b, b->parent);
b = b->next;
}
diff --git a/src/nxt_event_conn_proxy.c b/src/nxt_event_conn_proxy.c
index 0b9afe95..0a2a6474 100644
--- a/src/nxt_event_conn_proxy.c
+++ b/src/nxt_event_conn_proxy.c
@@ -7,53 +7,51 @@
#include <nxt_main.h>
-static void nxt_event_conn_proxy_client_buffer_alloc(nxt_thread_t *thr,
+static void nxt_event_conn_proxy_client_buffer_alloc(nxt_task_t *task,
void *obj, void *data);
-static void nxt_event_conn_proxy_peer_connect(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_proxy_peer_connect(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_proxy_connected(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_proxy_connected(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_proxy_peer_read(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_proxy_peer_read(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_proxy_client_read_ready(nxt_thread_t *thr,
- void *obj, void *data);
-static void nxt_event_conn_proxy_peer_read_ready(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_proxy_client_read_ready(nxt_task_t *task, void *obj,
+ void *data);
+static void nxt_event_conn_proxy_peer_read_ready(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_proxy_read_process(nxt_thread_t *thr,
+static void nxt_event_conn_proxy_read_process(nxt_task_t *task,
nxt_event_conn_proxy_t *p, nxt_event_conn_t *source,
nxt_event_conn_t *sink);
static void nxt_event_conn_proxy_write_add(nxt_event_conn_t *c, nxt_buf_t *b);
-static void nxt_event_conn_proxy_read(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_event_conn_proxy_client_write_ready(nxt_thread_t *thr,
- void *obj, void *data);
-static void nxt_event_conn_proxy_peer_write_ready(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_proxy_read(nxt_task_t *task, void *obj, void *data);
+static void nxt_event_conn_proxy_client_write_ready(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_proxy_write_process(nxt_thread_t *thr,
+static void nxt_event_conn_proxy_peer_write_ready(nxt_task_t *task, void *obj,
+ void *data);
+static void nxt_event_conn_proxy_write_process(nxt_task_t *task,
nxt_event_conn_proxy_t *p, nxt_event_conn_t *sink,
nxt_event_conn_t *source);
static void nxt_event_conn_proxy_read_add(nxt_event_conn_t *c, nxt_buf_t *b);
-static void nxt_event_conn_proxy_close(nxt_thread_t *thr, void *obj,
- void *data);
-static void nxt_event_conn_proxy_error(nxt_thread_t *thr, void *obj,
- void *data);
-static void nxt_event_conn_proxy_read_timeout(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_proxy_close(nxt_task_t *task, void *obj, void *data);
+static void nxt_event_conn_proxy_error(nxt_task_t *task, void *obj, void *data);
+static void nxt_event_conn_proxy_read_timeout(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_proxy_write_timeout(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_proxy_write_timeout(nxt_task_t *task, void *obj,
void *data);
static nxt_msec_t nxt_event_conn_proxy_timeout_value(nxt_event_conn_t *c,
uintptr_t data);
-static void nxt_event_conn_proxy_refused(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_proxy_refused(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_proxy_reconnect_handler(nxt_thread_t *thr,
- void *obj, void *data);
-static void nxt_event_conn_proxy_shutdown(nxt_thread_t *thr,
+static void nxt_event_conn_proxy_reconnect_handler(nxt_task_t *task, void *obj,
+ void *data);
+static void nxt_event_conn_proxy_shutdown(nxt_task_t *task,
nxt_event_conn_proxy_t *p, nxt_event_conn_t *source,
nxt_event_conn_t *sink);
-static void nxt_event_conn_proxy_read_error(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_proxy_read_error(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_proxy_write_error(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_proxy_write_error(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_conn_proxy_complete(nxt_thread_t *thr,
+static void nxt_event_conn_proxy_complete(nxt_task_t *task,
nxt_event_conn_proxy_t *p);
@@ -107,7 +105,7 @@ nxt_event_conn_proxy_create(nxt_event_conn_t *client)
void
-nxt_event_conn_proxy(nxt_event_conn_proxy_t *p)
+nxt_event_conn_proxy(nxt_task_t *task, nxt_event_conn_proxy_t *p)
{
nxt_thread_t *thr;
nxt_event_conn_t *peer;
@@ -127,7 +125,7 @@ nxt_event_conn_proxy(nxt_event_conn_proxy_t *p)
peer = p->peer;
peer->write_state = &nxt_event_conn_proxy_peer_connect_state;
- nxt_event_conn_connect_enqueue(thr, peer);
+ nxt_event_conn_connect_enqueue(thr, task, peer);
}
/*
@@ -136,7 +134,7 @@ nxt_event_conn_proxy(nxt_event_conn_proxy_t *p)
*/
p->client->read_state = &nxt_event_conn_proxy_client_wait_state;
- nxt_event_conn_read(thr, p->client);
+ nxt_event_conn_read(task, p->client);
}
@@ -157,7 +155,7 @@ static const nxt_event_conn_state_t nxt_event_conn_proxy_client_wait_state
static void
-nxt_event_conn_proxy_client_buffer_alloc(nxt_thread_t *thr, void *obj,
+nxt_event_conn_proxy_client_buffer_alloc(nxt_task_t *task, void *obj,
void *data)
{
nxt_buf_t *b;
@@ -167,15 +165,15 @@ nxt_event_conn_proxy_client_buffer_alloc(nxt_thread_t *thr, void *obj,
client = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy client first read fd:%d",
- client->socket.fd);
+ nxt_debug(task, "event conn proxy client first read fd:%d",
+ client->socket.fd);
b = nxt_buf_mem_alloc(client->mem_pool, p->client_buffer_size,
NXT_MEM_BUF_CUTBACK | NXT_MEM_BUF_USABLE);
if (nxt_slow_path(b == NULL)) {
/* An error completion. */
- nxt_event_conn_proxy_complete(thr, p);
+ nxt_event_conn_proxy_complete(task, p);
return;
}
@@ -203,7 +201,7 @@ nxt_event_conn_proxy_client_buffer_alloc(nxt_thread_t *thr, void *obj,
client->read_state = &nxt_event_conn_proxy_client_first_read_state;
}
- nxt_event_conn_read(thr, client);
+ nxt_event_conn_read(task, client);
}
@@ -224,7 +222,7 @@ static const nxt_event_conn_state_t
static void
-nxt_event_conn_proxy_peer_connect(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_peer_connect(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *client;
nxt_event_conn_proxy_t *p;
@@ -243,7 +241,7 @@ nxt_event_conn_proxy_peer_connect(nxt_thread_t *thr, void *obj, void *data)
p->peer->write_state = &nxt_event_conn_proxy_peer_connect_state;
- nxt_event_conn_connect(thr, p->peer);
+ nxt_event_conn_connect(task, p->peer);
}
@@ -264,7 +262,7 @@ static const nxt_event_conn_state_t nxt_event_conn_proxy_peer_connect_state
static void
-nxt_event_conn_proxy_connected(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_connected(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *client, *peer;
nxt_event_conn_proxy_t *p;
@@ -272,8 +270,7 @@ nxt_event_conn_proxy_connected(nxt_thread_t *thr, void *obj, void *data)
peer = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy connected fd:%d",
- peer->socket.fd);
+ nxt_debug(task, "event conn proxy connected fd:%d", peer->socket.fd);
p->connected = 1;
@@ -285,7 +282,7 @@ nxt_event_conn_proxy_connected(nxt_thread_t *thr, void *obj, void *data)
peer->read_state = &nxt_event_conn_proxy_peer_wait_state;
peer->write_state = &nxt_event_conn_proxy_peer_write_state;
- nxt_event_conn_read_enqueue(thr, peer);
+ nxt_event_conn_read_enqueue(task->thread, task, peer);
if (p->client_buffer != NULL) {
client = p->client;
@@ -296,7 +293,7 @@ nxt_event_conn_proxy_connected(nxt_thread_t *thr, void *obj, void *data)
* Send a client read data to the connected peer.
* Client write event: blocked.
*/
- nxt_event_conn_proxy_read_process(thr, p, client, peer);
+ nxt_event_conn_proxy_read_process(task, p, client, peer);
}
}
@@ -318,7 +315,7 @@ static const nxt_event_conn_state_t nxt_event_conn_proxy_peer_wait_state
static void
-nxt_event_conn_proxy_peer_read(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_peer_read(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b;
nxt_event_conn_t *peer;
@@ -327,15 +324,14 @@ nxt_event_conn_proxy_peer_read(nxt_thread_t *thr, void *obj, void *data)
peer = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy peer read fd:%d",
- peer->socket.fd);
+ nxt_debug(task, "event conn proxy peer read fd:%d", peer->socket.fd);
b = nxt_buf_mem_alloc(peer->mem_pool, p->peer_buffer_size,
NXT_MEM_BUF_CUTBACK | NXT_MEM_BUF_USABLE);
if (nxt_slow_path(b == NULL)) {
/* An error completion. */
- nxt_event_conn_proxy_complete(thr, p);
+ nxt_event_conn_proxy_complete(task, p);
return;
}
@@ -352,7 +348,7 @@ nxt_event_conn_proxy_peer_read(nxt_thread_t *thr, void *obj, void *data)
* Peer read event: waiting with possible peer_wait_timeout.
* Peer write event: blocked.
*/
- nxt_event_conn_read(thr, peer);
+ nxt_event_conn_read(task, peer);
}
@@ -373,8 +369,7 @@ static const nxt_event_conn_state_t nxt_event_conn_proxy_client_read_state
static void
-nxt_event_conn_proxy_client_read_ready(nxt_thread_t *thr, void *obj,
- void *data)
+nxt_event_conn_proxy_client_read_ready(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *client;
nxt_event_conn_proxy_t *p;
@@ -382,10 +377,10 @@ nxt_event_conn_proxy_client_read_ready(nxt_thread_t *thr, void *obj,
client = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy client read ready fd:%d",
- client->socket.fd);
+ nxt_debug(task, "event conn proxy client read ready fd:%d",
+ client->socket.fd);
- nxt_event_conn_proxy_read_process(thr, p, client, p->peer);
+ nxt_event_conn_proxy_read_process(task, p, client, p->peer);
}
@@ -406,8 +401,7 @@ static const nxt_event_conn_state_t nxt_event_conn_proxy_peer_read_state
static void
-nxt_event_conn_proxy_peer_read_ready(nxt_thread_t *thr, void *obj,
- void *data)
+nxt_event_conn_proxy_peer_read_ready(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *peer;
nxt_event_conn_proxy_t *p;
@@ -415,24 +409,23 @@ nxt_event_conn_proxy_peer_read_ready(nxt_thread_t *thr, void *obj,
peer = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy peer read ready fd:%d",
- peer->socket.fd);
+ nxt_debug(task, "event conn proxy peer read ready fd:%d", peer->socket.fd);
- nxt_event_conn_proxy_read_process(thr, p, peer, p->client);
+ nxt_event_conn_proxy_read_process(task, p, peer, p->client);
}
static void
-nxt_event_conn_proxy_read_process(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
+nxt_event_conn_proxy_read_process(nxt_task_t *task, nxt_event_conn_proxy_t *p,
nxt_event_conn_t *source, nxt_event_conn_t *sink)
{
nxt_buf_t *rb, *wb;
if (sink->socket.error != 0) {
- nxt_log_debug(thr->log, "event conn proxy sink fd:%d error:%d",
- sink->socket.fd, sink->socket.error);
+ nxt_debug(task, "event conn proxy sink fd:%d error:%d",
+ sink->socket.fd, sink->socket.error);
- nxt_event_conn_proxy_write_error(thr, sink, sink->socket.data);
+ nxt_event_conn_proxy_write_error(task, sink, sink->socket.data);
return;
}
@@ -447,7 +440,7 @@ nxt_event_conn_proxy_read_process(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
wb = nxt_buf_mem_alloc(source->mem_pool, 0, 0);
if (wb == NULL) {
/* An error completion. */
- nxt_event_conn_proxy_complete(thr, p);
+ nxt_event_conn_proxy_complete(task, p);
return;
}
@@ -463,10 +456,9 @@ nxt_event_conn_proxy_read_process(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
}
if (rb->mem.start != rb->mem.end) {
- nxt_thread_work_queue_push(thr, source->read_work_queue,
+ nxt_thread_work_queue_push(task->thread, source->read_work_queue,
nxt_event_conn_proxy_read,
- source, source->socket.data,
- source->socket.log);
+ task, source, source->socket.data);
break;
}
@@ -475,7 +467,7 @@ nxt_event_conn_proxy_read_process(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
}
if (p->connected) {
- nxt_event_conn_write_enqueue(thr, sink);
+ nxt_event_conn_write_enqueue(task->thread, task, sink);
}
}
@@ -539,7 +531,7 @@ nxt_event_conn_proxy_write_add(nxt_event_conn_t *c, nxt_buf_t *b)
static void
-nxt_event_conn_proxy_read(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_read(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *source, *sink;
nxt_event_conn_proxy_t *p;
@@ -547,13 +539,13 @@ nxt_event_conn_proxy_read(nxt_thread_t *thr, void *obj, void *data)
source = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy read fd:%d", source->socket.fd);
+ nxt_debug(task, "event conn proxy read fd:%d", source->socket.fd);
if (!source->socket.closed) {
sink = (source == p->client) ? p->peer : p->client;
if (sink->socket.error == 0) {
- nxt_event_conn_read(thr, source);
+ nxt_event_conn_read(task, source);
}
}
}
@@ -576,8 +568,7 @@ static const nxt_event_conn_state_t nxt_event_conn_proxy_client_write_state
static void
-nxt_event_conn_proxy_client_write_ready(nxt_thread_t *thr, void *obj,
- void *data)
+nxt_event_conn_proxy_client_write_ready(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *client;
nxt_event_conn_proxy_t *p;
@@ -585,10 +576,10 @@ nxt_event_conn_proxy_client_write_ready(nxt_thread_t *thr, void *obj,
client = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy client write ready fd:%d",
- client->socket.fd);
+ nxt_debug(task, "event conn proxy client write ready fd:%d",
+ client->socket.fd);
- nxt_event_conn_proxy_write_process(thr, p, client, p->peer);
+ nxt_event_conn_proxy_write_process(task, p, client, p->peer);
}
@@ -609,7 +600,7 @@ static const nxt_event_conn_state_t nxt_event_conn_proxy_peer_write_state
static void
-nxt_event_conn_proxy_peer_write_ready(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_peer_write_ready(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *peer;
nxt_event_conn_proxy_t *p;
@@ -617,15 +608,14 @@ nxt_event_conn_proxy_peer_write_ready(nxt_thread_t *thr, void *obj, void *data)
peer = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy peer write ready fd:%d",
- peer->socket.fd);
+ nxt_debug(task, "event conn proxy peer write ready fd:%d", peer->socket.fd);
- nxt_event_conn_proxy_write_process(thr, p, peer, p->client);
+ nxt_event_conn_proxy_write_process(task, p, peer, p->client);
}
static void
-nxt_event_conn_proxy_write_process(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
+nxt_event_conn_proxy_write_process(nxt_task_t *task, nxt_event_conn_proxy_t *p,
nxt_event_conn_t *sink, nxt_event_conn_t *source)
{
nxt_buf_t *rb, *wb;
@@ -640,7 +630,7 @@ nxt_event_conn_proxy_write_process(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
sink->write = NULL;
nxt_buf_free(sink->mem_pool, wb);
- nxt_event_conn_proxy_shutdown(thr, p, source, sink);
+ nxt_event_conn_proxy_shutdown(task, p, source, sink);
return;
}
@@ -651,7 +641,7 @@ nxt_event_conn_proxy_write_process(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
rb = nxt_buf_mem_alloc(sink->mem_pool, 0, 0);
if (rb == NULL) {
/* An error completion. */
- nxt_event_conn_proxy_complete(thr, p);
+ nxt_event_conn_proxy_complete(task, p);
return;
}
@@ -666,7 +656,7 @@ nxt_event_conn_proxy_write_process(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
}
if (wb->mem.pos != wb->mem.free) {
- nxt_event_conn_write_enqueue(thr, sink);
+ nxt_event_conn_write_enqueue(task->thread, task, sink);
break;
}
@@ -675,9 +665,9 @@ nxt_event_conn_proxy_write_process(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
nxt_buf_free(sink->mem_pool, wb);
}
- nxt_thread_work_queue_push(thr, source->read_work_queue,
- nxt_event_conn_proxy_read, source,
- source->socket.data, source->socket.log);
+ nxt_thread_work_queue_push(task->thread, source->read_work_queue,
+ nxt_event_conn_proxy_read, task, source,
+ source->socket.data);
}
@@ -760,7 +750,7 @@ nxt_event_conn_proxy_read_add(nxt_event_conn_t *c, nxt_buf_t *b)
static void
-nxt_event_conn_proxy_close(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_close(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b;
nxt_event_conn_t *source, *sink;
@@ -769,19 +759,19 @@ nxt_event_conn_proxy_close(nxt_thread_t *thr, void *obj, void *data)
source = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy close fd:%d", source->socket.fd);
+ nxt_debug(task, "event conn proxy close fd:%d", source->socket.fd);
sink = (source == p->client) ? p->peer : p->client;
if (sink->write == NULL) {
- nxt_event_conn_proxy_shutdown(thr, p, source, sink);
+ nxt_event_conn_proxy_shutdown(task, p, source, sink);
return;
}
b = nxt_buf_sync_alloc(source->mem_pool, 0);
if (b == NULL) {
/* An error completion. */
- nxt_event_conn_proxy_complete(thr, p);
+ nxt_event_conn_proxy_complete(task, p);
return;
}
@@ -790,7 +780,7 @@ nxt_event_conn_proxy_close(nxt_thread_t *thr, void *obj, void *data)
static void
-nxt_event_conn_proxy_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_error(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_event_conn_proxy_t *p;
@@ -798,14 +788,14 @@ nxt_event_conn_proxy_error(nxt_thread_t *thr, void *obj, void *data)
c = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy error fd:%d", c->socket.fd);
+ nxt_debug(task, "event conn proxy error fd:%d", c->socket.fd);
- nxt_event_conn_proxy_close(thr, c, p);
+ nxt_event_conn_proxy_close(task, c, p);
}
static void
-nxt_event_conn_proxy_read_timeout(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_read_timeout(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_event_timer_t *ev;
@@ -816,15 +806,14 @@ nxt_event_conn_proxy_read_timeout(nxt_thread_t *thr, void *obj, void *data)
c->socket.timedout = 1;
c->socket.closed = 1;
- nxt_log_debug(thr->log, "event conn proxy read timeout fd:%d",
- c->socket.fd);
+ nxt_debug(task, "event conn proxy read timeout fd:%d", c->socket.fd);
- nxt_event_conn_proxy_close(thr, c, c->socket.data);
+ nxt_event_conn_proxy_close(task, c, c->socket.data);
}
static void
-nxt_event_conn_proxy_write_timeout(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_write_timeout(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_event_timer_t *ev;
@@ -835,10 +824,9 @@ nxt_event_conn_proxy_write_timeout(nxt_thread_t *thr, void *obj, void *data)
c->socket.timedout = 1;
c->socket.closed = 1;
- nxt_log_debug(thr->log, "event conn proxy write timeout fd:%d",
- c->socket.fd);
+ nxt_debug(task, "event conn proxy write timeout fd:%d", c->socket.fd);
- nxt_event_conn_proxy_close(thr, c, c->socket.data);
+ nxt_event_conn_proxy_close(task, c, c->socket.data);
}
@@ -857,7 +845,7 @@ nxt_event_conn_proxy_timeout_value(nxt_event_conn_t *c, uintptr_t data)
static void
-nxt_event_conn_proxy_refused(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_refused(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *peer;
nxt_event_conn_proxy_t *p;
@@ -865,11 +853,11 @@ nxt_event_conn_proxy_refused(nxt_thread_t *thr, void *obj, void *data)
peer = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy refused fd:%d", peer->socket.fd);
+ nxt_debug(task, "event conn proxy refused fd:%d", peer->socket.fd);
if (p->retries == 0) {
/* An error completion. */
- nxt_event_conn_proxy_complete(thr, p);
+ nxt_event_conn_proxy_complete(task, p);
return;
}
@@ -882,13 +870,13 @@ nxt_event_conn_proxy_refused(nxt_thread_t *thr, void *obj, void *data)
p->delayed = 1;
peer->write_timer.handler = nxt_event_conn_proxy_reconnect_handler;
- nxt_event_timer_add(thr->engine, &peer->write_timer, p->reconnect_timeout);
+ nxt_event_timer_add(task->thread->engine, &peer->write_timer,
+ p->reconnect_timeout);
}
static void
-nxt_event_conn_proxy_reconnect_handler(nxt_thread_t *thr, void *obj,
- void *data)
+nxt_event_conn_proxy_reconnect_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *peer;
nxt_event_timer_t *ev;
@@ -896,13 +884,13 @@ nxt_event_conn_proxy_reconnect_handler(nxt_thread_t *thr, void *obj,
ev = obj;
- nxt_log_debug(thr->log, "event conn proxy reconnect timer");
+ nxt_debug(task, "event conn proxy reconnect timer");
peer = nxt_event_write_timer_conn(ev);
p = peer->socket.data;
if (p->client->socket.closed) {
- nxt_event_conn_proxy_complete(thr, p);
+ nxt_event_conn_proxy_complete(task, p);
return;
}
@@ -913,27 +901,27 @@ nxt_event_conn_proxy_reconnect_handler(nxt_thread_t *thr, void *obj,
* Peer read event: disabled.
* Peer write event: waiting for connection with connect_timeout.
*/
- nxt_event_conn_connect(thr, peer);
+ nxt_event_conn_connect(task, peer);
}
static void
-nxt_event_conn_proxy_shutdown(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
+nxt_event_conn_proxy_shutdown(nxt_task_t *task, nxt_event_conn_proxy_t *p,
nxt_event_conn_t *source, nxt_event_conn_t *sink)
{
nxt_buf_t *b;
- nxt_log_debug(source->socket.log,
- "event conn proxy shutdown source fd:%d cl:%d err:%d",
- source->socket.fd, source->socket.closed,
- source->socket.error);
+ nxt_debug(source->socket.task,
+ "event conn proxy shutdown source fd:%d cl:%d err:%d",
+ source->socket.fd, source->socket.closed,
+ source->socket.error);
- nxt_log_debug(sink->socket.log,
- "event conn proxy shutdown sink fd:%d cl:%d err:%d",
- sink->socket.fd, sink->socket.closed, sink->socket.error);
+ nxt_debug(sink->socket.task,
+ "event conn proxy shutdown sink fd:%d cl:%d err:%d",
+ sink->socket.fd, sink->socket.closed, sink->socket.error);
if (!p->connected || p->delayed) {
- nxt_event_conn_proxy_complete(thr, p);
+ nxt_event_conn_proxy_complete(task, p);
return;
}
@@ -943,7 +931,7 @@ nxt_event_conn_proxy_shutdown(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
* remote side so the shutdown() syscall is surplus
* since the close() syscall also sends FIN.
*/
- nxt_event_conn_close(thr, sink);
+ nxt_event_conn_close(task, sink);
} else {
nxt_socket_shutdown(sink->socket.fd, SHUT_WR);
@@ -953,7 +941,7 @@ nxt_event_conn_proxy_shutdown(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
|| (sink->socket.closed && source->write == NULL))
{
/* The opposite direction also has been already closed. */
- nxt_event_conn_proxy_complete(thr, p);
+ nxt_event_conn_proxy_complete(task, p);
return;
}
@@ -964,7 +952,7 @@ nxt_event_conn_proxy_shutdown(nxt_thread_t *thr, nxt_event_conn_proxy_t *p,
static void
-nxt_event_conn_proxy_read_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_read_error(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_event_conn_proxy_t *p;
@@ -972,14 +960,14 @@ nxt_event_conn_proxy_read_error(nxt_thread_t *thr, void *obj, void *data)
c = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy read error fd:%d", c->socket.fd);
+ nxt_debug(task, "event conn proxy read error fd:%d", c->socket.fd);
- nxt_event_conn_proxy_close(thr, c, p);
+ nxt_event_conn_proxy_close(task, c, p);
}
static void
-nxt_event_conn_proxy_write_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_proxy_write_error(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *source, *sink;
nxt_event_conn_proxy_t *p;
@@ -987,48 +975,47 @@ nxt_event_conn_proxy_write_error(nxt_thread_t *thr, void *obj, void *data)
sink = obj;
p = data;
- nxt_log_debug(thr->log, "event conn proxy write error fd:%d",
- sink->socket.fd);
+ nxt_debug(task, "event conn proxy write error fd:%d", sink->socket.fd);
/* Clear data for the direction sink. */
sink->write = NULL;
/* Block the direction source. */
source = (sink == p->client) ? p->peer : p->client;
- nxt_event_fd_block_read(thr->engine, &source->socket);
+ nxt_event_fd_block_read(task->thread->engine, &source->socket);
if (source->write == NULL) {
/*
* There is no data for the opposite direction and
* the next read from the sink will most probably fail.
*/
- nxt_event_conn_proxy_complete(thr, p);
+ nxt_event_conn_proxy_complete(task, p);
}
}
static void
-nxt_event_conn_proxy_complete(nxt_thread_t *thr, nxt_event_conn_proxy_t *p)
+nxt_event_conn_proxy_complete(nxt_task_t *task, nxt_event_conn_proxy_t *p)
{
- nxt_log_debug(p->client->socket.log, "event conn proxy complete %d:%d",
- p->client->socket.fd, p->peer->socket.fd);
+ nxt_debug(p->client->socket.task, "event conn proxy complete %d:%d",
+ p->client->socket.fd, p->peer->socket.fd);
if (p->client->socket.fd != -1) {
- nxt_event_conn_close(thr, p->client);
+ nxt_event_conn_close(task, p->client);
}
if (p->peer->socket.fd != -1) {
- nxt_event_conn_close(thr, p->peer);
+ nxt_event_conn_close(task, p->peer);
} else if (p->delayed) {
- nxt_thread_work_queue_drop(thr, &p->peer->write_timer);
+ nxt_thread_work_queue_drop(task->thread, &p->peer->write_timer);
nxt_queue_remove(&p->peer->link);
- nxt_event_timer_delete(thr->engine, &p->peer->write_timer);
+ nxt_event_timer_delete(task->thread->engine, &p->peer->write_timer);
}
nxt_mem_free(p->client->mem_pool, p->client_buffer);
nxt_mem_free(p->client->mem_pool, p->peer_buffer);
- p->completion_handler(thr, p, NULL);
+ p->completion_handler(task, p, NULL);
}
diff --git a/src/nxt_event_conn_read.c b/src/nxt_event_conn_read.c
index 59d7d59c..f6bbbbd8 100644
--- a/src/nxt_event_conn_read.c
+++ b/src/nxt_event_conn_read.c
@@ -8,43 +8,46 @@
void
-nxt_event_conn_read(nxt_thread_t *thr, nxt_event_conn_t *c)
+nxt_event_conn_read(nxt_task_t *task, nxt_event_conn_t *c)
{
nxt_work_queue_t *wq;
nxt_work_handler_t handler;
handler = c->io->read;
- if (thr->engine->batch != 0) {
+ if (task->thread->engine->batch != 0) {
- wq = &thr->engine->read_work_queue;
+ wq = &task->thread->engine->read_work_queue;
c->socket.read_work_queue = wq;
- nxt_thread_work_queue_add(thr, wq, handler, c, c->socket.data,
- c->socket.log);
+ nxt_thread_work_queue_add(task->thread, wq, handler, task, c,
+ c->socket.data);
return;
}
- handler(thr, c, c->socket.data);
+ handler(task, c, c->socket.data);
}
void
-nxt_event_conn_io_read(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_io_read(nxt_task_t *task, void *obj, void *data)
{
ssize_t n;
nxt_buf_t *b;
nxt_bool_t batch;
nxt_event_conn_t *c;
+ nxt_event_engine_t *engine;
nxt_work_handler_t handler;
const nxt_event_conn_state_t *state;
c = obj;
- nxt_log_debug(thr->log, "event conn read fd:%d rdy:%d cl:%d",
- c->socket.fd, c->socket.read_ready, c->socket.closed);
+ nxt_debug(task, "event conn read fd:%d rdy:%d cl:%d",
+ c->socket.fd, c->socket.read_ready, c->socket.closed);
- batch = (thr->engine->batch != 0);
+ engine = task->thread->engine;
+
+ batch = (engine->batch != 0);
state = c->read_state;
if (c->socket.read_ready) {
@@ -83,7 +86,7 @@ nxt_event_conn_io_read(nxt_thread_t *thr, void *obj, void *data)
}
if (n != NXT_AGAIN) {
- nxt_event_fd_block_read(thr->engine, &c->socket);
+ nxt_event_fd_block_read(engine, &c->socket);
nxt_event_timer_disable(&c->read_timer);
if (n == 0) {
@@ -109,10 +112,10 @@ nxt_event_conn_io_read(nxt_thread_t *thr, void *obj, void *data)
|| nxt_event_fd_is_disabled(c->socket.read))
{
/* Timer may be set or reset. */
- nxt_event_conn_timer(thr->engine, c, state, &c->read_timer);
+ nxt_event_conn_timer(engine, c, state, &c->read_timer);
if (nxt_event_fd_is_disabled(c->socket.read)) {
- nxt_event_fd_enable_read(thr->engine, &c->socket);
+ nxt_event_fd_enable_read(engine, &c->socket);
}
}
@@ -120,7 +123,7 @@ nxt_event_conn_io_read(nxt_thread_t *thr, void *obj, void *data)
ready:
- nxt_event_fd_block_read(thr->engine, &c->socket);
+ nxt_event_fd_block_read(engine, &c->socket);
if (state->autoreset_timer) {
nxt_event_timer_disable(&c->read_timer);
@@ -131,10 +134,10 @@ ready:
done:
if (batch) {
- nxt_thread_work_queue_add(thr, c->read_work_queue, handler,
- c, data, thr->log);
+ nxt_thread_work_queue_add(task->thread, c->read_work_queue, handler,
+ task, c, data);
} else {
- handler(thr, c, data);
+ handler(task, c, data);
}
}
@@ -165,8 +168,7 @@ nxt_event_conn_io_recvbuf(nxt_event_conn_t *c, nxt_buf_t *b)
err = (n == -1) ? nxt_socket_errno : 0;
- nxt_log_debug(c->socket.log, "readv(%d, %ui): %z",
- c->socket.fd, niov, n);
+ nxt_debug(c->socket.task, "readv(%d, %ui): %z", c->socket.fd, niov, n);
if (n > 0) {
if ((size_t) n < rb.size) {
@@ -187,12 +189,12 @@ nxt_event_conn_io_recvbuf(nxt_event_conn_t *c, nxt_buf_t *b)
switch (err) {
case NXT_EAGAIN:
- nxt_log_debug(c->socket.log, "readv() %E", err);
+ nxt_debug(c->socket.task, "readv() %E", err);
c->socket.read_ready = 0;
return NXT_AGAIN;
case NXT_EINTR:
- nxt_log_debug(c->socket.log, "readv() %E", err);
+ nxt_debug(c->socket.task, "readv() %E", err);
continue;
default:
@@ -218,8 +220,8 @@ nxt_event_conn_io_recv(nxt_event_conn_t *c, void *buf, size_t size,
err = (n == -1) ? nxt_socket_errno : 0;
- nxt_log_debug(c->socket.log, "recv(%d, %p, %uz, 0x%ui): %z",
- c->socket.fd, buf, size, flags, n);
+ nxt_debug(c->socket.task, "recv(%d, %p, %uz, 0x%ui): %z",
+ c->socket.fd, buf, size, flags, n);
if (n > 0) {
if ((size_t) n < size) {
diff --git a/src/nxt_event_conn_write.c b/src/nxt_event_conn_write.c
index 0f35b5f3..d72ddc80 100644
--- a/src/nxt_event_conn_write.c
+++ b/src/nxt_event_conn_write.c
@@ -11,38 +11,41 @@ static void nxt_event_conn_average_rate_update(nxt_event_write_rate_t *rate,
size_t sent, nxt_msec_t now);
NXT_LIB_UNIT_TEST_STATIC double
nxt_event_conn_exponential_approximation(double n);
-static void nxt_event_conn_write_timer_handler(nxt_thread_t *thr, void *obj,
+static void nxt_event_conn_write_timer_handler(nxt_task_t *task, void *obj,
void *data);
void
-nxt_event_conn_write(nxt_thread_t *thr, nxt_event_conn_t *c)
+nxt_event_conn_write(nxt_task_t *task, nxt_event_conn_t *c)
{
- if (thr->engine->batch != 0) {
- nxt_event_conn_write_enqueue(thr, c);
+ if (task->thread->engine->batch != 0) {
+ nxt_event_conn_write_enqueue(task->thread, task, c);
} else {
- c->io->write(thr, c, c->socket.data);
+ c->io->write(task, c, c->socket.data);
}
}
void
-nxt_event_conn_io_write(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_io_write(nxt_task_t *task, void *obj, void *data)
{
- size_t sent, limit;
- ssize_t ret;
- nxt_buf_t *b;
- nxt_event_conn_t *c;
+ size_t sent, limit;
+ ssize_t ret;
+ nxt_buf_t *b;
+ nxt_event_conn_t *c;
+ nxt_event_engine_t *engine;
c = obj;
- nxt_log_debug(thr->log, "event conn write fd:%d", c->socket.fd);
+ nxt_debug(task, "event conn write fd:%d", c->socket.fd);
if (!c->socket.write_ready || c->delayed || c->write == NULL) {
return;
}
+ engine = task->thread->engine;
+
c->socket.write_handler = nxt_event_conn_io_write;
c->socket.error_handler = c->write_state->error_handler;
@@ -54,7 +57,7 @@ nxt_event_conn_io_write(nxt_thread_t *thr, void *obj, void *data)
while (limit != 0) {
- ret = c->io->write_chunk(thr, c, b, limit);
+ ret = c->io->write_chunk(c, b, limit);
if (ret < 0) {
/* ret == NXT_AGAIN || ret == NXT_ERROR. */
@@ -65,7 +68,7 @@ nxt_event_conn_io_write(nxt_thread_t *thr, void *obj, void *data)
limit -= ret;
if (c->write_state->process_buffers) {
- b = nxt_sendbuf_completion(thr, c->write_work_queue, b, ret);
+ b = nxt_sendbuf_completion(task, c->write_work_queue, b, ret);
c->write = b;
} else {
@@ -73,7 +76,7 @@ nxt_event_conn_io_write(nxt_thread_t *thr, void *obj, void *data)
}
if (b == NULL) {
- nxt_event_fd_block_write(thr->engine, &c->socket);
+ nxt_event_fd_block_write(engine, &c->socket);
break;
}
@@ -83,7 +86,7 @@ nxt_event_conn_io_write(nxt_thread_t *thr, void *obj, void *data)
}
}
- nxt_log_debug(thr->log, "event conn: %i sent:%z", ret, sent);
+ nxt_debug(task, "event conn: %i sent:%z", ret, sent);
if (sent != 0) {
if (c->write_state->autoreset_timer) {
@@ -92,7 +95,7 @@ nxt_event_conn_io_write(nxt_thread_t *thr, void *obj, void *data)
}
if (ret != NXT_ERROR
- && !nxt_event_conn_write_delayed(thr->engine, c, sent))
+ && !nxt_event_conn_write_delayed(engine, c, sent))
{
if (limit == 0) {
/*
@@ -100,7 +103,7 @@ nxt_event_conn_io_write(nxt_thread_t *thr, void *obj, void *data)
* process other recevied events and to get new events.
*/
c->write_timer.handler = nxt_event_conn_write_timer_handler;
- nxt_event_timer_add(thr->engine, &c->write_timer, 0);
+ nxt_event_timer_add(engine, &c->write_timer, 0);
} else if (ret == NXT_AGAIN) {
/*
@@ -110,16 +113,15 @@ nxt_event_conn_io_write(nxt_thread_t *thr, void *obj, void *data)
* can be set here because it should be set only for write
* direction.
*/
- nxt_event_conn_timer(thr->engine, c, c->write_state,
- &c->write_timer);
+ nxt_event_conn_timer(engine, c, c->write_state, &c->write_timer);
}
}
if (ret == 0 || sent != 0) {
/* "ret == 0" means a sync buffer was processed. */
c->sent += sent;
- nxt_event_conn_io_handle(thr, c->write_work_queue,
- c->write_state->ready_handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue,
+ c->write_state->ready_handler, task, c, data);
/*
* Fall through if first operations were
* successful but the last one failed.
@@ -127,10 +129,10 @@ nxt_event_conn_io_write(nxt_thread_t *thr, void *obj, void *data)
}
if (nxt_slow_path(ret == NXT_ERROR)) {
- nxt_event_fd_block_write(thr->engine, &c->socket);
+ nxt_event_fd_block_write(engine, &c->socket);
- nxt_event_conn_io_handle(thr, c->write_work_queue,
- c->write_state->error_handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue,
+ c->write_state->error_handler, task, c, data);
}
}
@@ -284,25 +286,24 @@ nxt_event_conn_exponential_approximation(double x)
static void
-nxt_event_conn_write_timer_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_conn_write_timer_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_event_timer_t *ev;
ev = obj;
- nxt_log_debug(thr->log, "event conn conn timer");
+ nxt_debug(task, "event conn conn timer");
c = nxt_event_write_timer_conn(ev);
c->delayed = 0;
- c->io->write(thr, c, c->socket.data);
+ c->io->write(task, c, c->socket.data);
}
ssize_t
-nxt_event_conn_io_write_chunk(nxt_thread_t *thr, nxt_event_conn_t *c,
- nxt_buf_t *b, size_t limit)
+nxt_event_conn_io_write_chunk(nxt_event_conn_t *c, nxt_buf_t *b, size_t limit)
{
ssize_t ret;
@@ -311,7 +312,7 @@ nxt_event_conn_io_write_chunk(nxt_thread_t *thr, nxt_event_conn_t *c,
if ((ret == NXT_AGAIN || !c->socket.write_ready)
&& nxt_event_fd_is_disabled(c->socket.write))
{
- nxt_event_fd_enable_write(thr->engine, &c->socket);
+ nxt_event_fd_enable_write(c->socket.task->thread->engine, &c->socket);
}
return ret;
@@ -332,7 +333,7 @@ nxt_event_conn_io_sendbuf(nxt_event_conn_t *c, nxt_buf_t *b, size_t limit)
sb.size = 0;
sb.limit = limit;
- niob = nxt_sendbuf_mem_coalesce(&sb);
+ niob = nxt_sendbuf_mem_coalesce(c->socket.task, &sb);
if (niob == 0 && sb.sync) {
return 0;
@@ -400,8 +401,8 @@ nxt_event_conn_io_send(nxt_event_conn_t *c, void *buf, size_t size)
err = (n == -1) ? nxt_socket_errno : 0;
- nxt_log_debug(c->socket.log, "send(%d, %p, %uz): %z",
- c->socket.fd, buf, size, n);
+ nxt_debug(c->socket.task, "send(%d, %p, %uz): %z",
+ c->socket.fd, buf, size, n);
if (n > 0) {
return n;
@@ -412,19 +413,20 @@ nxt_event_conn_io_send(nxt_event_conn_t *c, void *buf, size_t size)
switch (err) {
case NXT_EAGAIN:
- nxt_log_debug(c->socket.log, "send() %E", err);
+ nxt_debug(c->socket.task, "send() %E", err);
c->socket.write_ready = 0;
return NXT_AGAIN;
case NXT_EINTR:
- nxt_log_debug(c->socket.log, "send() %E", err);
+ nxt_debug(c->socket.task, "send() %E", err);
continue;
default:
c->socket.error = err;
- nxt_log_error(nxt_socket_error_level(err, c->socket.log_error),
- c->socket.log, "send(%d, %p, %uz) failed %E",
- c->socket.fd, buf, size, err);
+ nxt_log(c->socket.task,
+ nxt_socket_error_level(err, c->socket.log_error),
+ "send(%d, %p, %uz) failed %E",
+ c->socket.fd, buf, size, err);
return NXT_ERROR;
}
}
diff --git a/src/nxt_event_engine.c b/src/nxt_event_engine.c
index dd0f5fe3..ead63b72 100644
--- a/src/nxt_event_engine.c
+++ b/src/nxt_event_engine.c
@@ -7,21 +7,20 @@
#include <nxt_main.h>
-static nxt_int_t nxt_event_engine_post_init(nxt_thread_t *thr,
+static nxt_int_t nxt_event_engine_post_init(nxt_event_engine_t *engine);
+static nxt_int_t nxt_event_engine_signal_pipe_create(
nxt_event_engine_t *engine);
-static nxt_int_t nxt_event_engine_signal_pipe_create(nxt_thread_t *thr,
- nxt_event_engine_t *engine);
-static void nxt_event_engine_signal_pipe_close(nxt_thread_t *thr, void *obj,
+static void nxt_event_engine_signal_pipe_close(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_engine_signal_pipe(nxt_thread_t *thr, void *obj,
+static void nxt_event_engine_signal_pipe(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_engine_post_handler(nxt_thread_t *thr, void *obj,
+static void nxt_event_engine_post_handler(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_engine_signal_pipe_error(nxt_thread_t *thr, void *obj,
+static void nxt_event_engine_signal_pipe_error(nxt_task_t *task, void *obj,
void *data);
-static void nxt_event_engine_signal_handler(nxt_thread_t *thr, void *obj,
+static void nxt_event_engine_signal_handler(nxt_task_t *task, void *obj,
void *data);
-static const nxt_event_sig_t *nxt_event_engine_signal_find(nxt_thread_t *thr,
+static const nxt_event_sig_t *nxt_event_engine_signal_find(nxt_task_t *task,
nxt_uint_t signo);
@@ -37,6 +36,13 @@ nxt_event_engine_create(nxt_thread_t *thr, const nxt_event_set_ops_t *event_set,
return NULL;
}
+ engine->task.thread = thr;
+ engine->task.log = thr->log;
+ engine->task.ident = nxt_task_next_ident();
+
+ thr->engine = engine;
+ thr->fiber = &engine->fibers->fiber;
+
engine->batch = batch;
if (flags & NXT_ENGINE_FIBERS) {
@@ -91,7 +97,7 @@ nxt_event_engine_create(nxt_thread_t *thr, const nxt_event_set_ops_t *event_set,
engine->event = event_set;
- if (nxt_event_engine_post_init(thr, engine) != NXT_OK) {
+ if (nxt_event_engine_post_init(engine) != NXT_OK) {
goto post_fail;
}
@@ -107,8 +113,7 @@ nxt_event_engine_create(nxt_thread_t *thr, const nxt_event_set_ops_t *event_set,
nxt_queue_init(&engine->listen_connections);
nxt_queue_init(&engine->idle_connections);
- thr->engine = engine;
- thr->fiber = &engine->fibers->fiber;
+ engine->thread = thr;
#if !(NXT_THREADS)
@@ -140,7 +145,7 @@ fibers_fail:
static nxt_int_t
-nxt_event_engine_post_init(nxt_thread_t *thr, nxt_event_engine_t *engine)
+nxt_event_engine_post_init(nxt_event_engine_t *engine)
{
if (engine->event->enable_post != NULL) {
return engine->event->enable_post(engine->event_set,
@@ -157,7 +162,7 @@ nxt_event_engine_post_init(nxt_thread_t *thr, nxt_event_engine_t *engine)
#endif
- if (nxt_event_engine_signal_pipe_create(thr, engine) != NXT_OK) {
+ if (nxt_event_engine_signal_pipe_create(engine) != NXT_OK) {
return NXT_ERROR;
}
@@ -166,8 +171,7 @@ nxt_event_engine_post_init(nxt_thread_t *thr, nxt_event_engine_t *engine)
static nxt_int_t
-nxt_event_engine_signal_pipe_create(nxt_thread_t *thr,
- nxt_event_engine_t *engine)
+nxt_event_engine_signal_pipe_create(nxt_event_engine_t *engine)
{
nxt_event_engine_pipe_t *pipe;
@@ -189,9 +193,9 @@ nxt_event_engine_signal_pipe_create(nxt_thread_t *thr,
}
pipe->event.fd = pipe->fds[0];
- pipe->event.read_work_queue = &thr->work_queue.main;
+ pipe->event.read_work_queue = &engine->task.thread->work_queue.main;
pipe->event.read_handler = nxt_event_engine_signal_pipe;
- pipe->event.write_work_queue = &thr->work_queue.main;
+ pipe->event.write_work_queue = &engine->task.thread->work_queue.main;
pipe->event.error_handler = nxt_event_engine_signal_pipe_error;
pipe->event.log = &nxt_main_log;
@@ -221,7 +225,7 @@ nxt_event_engine_signal_pipe_free(nxt_event_engine_t *engine)
static void
-nxt_event_engine_signal_pipe_close(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_engine_signal_pipe_close(nxt_task_t *task, void *obj, void *data)
{
nxt_event_engine_pipe_t *pipe;
@@ -234,11 +238,11 @@ nxt_event_engine_signal_pipe_close(nxt_thread_t *thr, void *obj, void *data)
void
nxt_event_engine_post(nxt_event_engine_t *engine, nxt_work_handler_t handler,
- void *obj, void *data, nxt_log_t *log)
+ nxt_task_t *task, void *obj, void *data, nxt_log_t *log)
{
nxt_thread_log_debug("event engine post");
- nxt_locked_work_queue_add(&engine->work_queue, handler, obj, data, log);
+ nxt_locked_work_queue_add(&engine->work_queue, handler, task, obj, data);
nxt_event_engine_signal(engine, 0);
}
@@ -267,7 +271,7 @@ nxt_event_engine_signal(nxt_event_engine_t *engine, nxt_uint_t signo)
static void
-nxt_event_engine_signal_pipe(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_engine_signal_pipe(nxt_task_t *task, void *obj, void *data)
{
int i, n;
u_char signo;
@@ -278,7 +282,7 @@ nxt_event_engine_signal_pipe(nxt_thread_t *thr, void *obj, void *data)
ev = obj;
- nxt_log_debug(thr->log, "engine signal pipe");
+ nxt_debug(task, "engine signal pipe");
post = 0;
@@ -288,17 +292,17 @@ nxt_event_engine_signal_pipe(nxt_thread_t *thr, void *obj, void *data)
for (i = 0; i < n; i++) {
signo = buf[i];
- nxt_log_debug(thr->log, "engine pipe signo:%d", signo);
+ nxt_debug(task, "engine pipe signo:%d", signo);
if (signo == 0) {
/* A post should be processed only once. */
post = 1;
} else {
- sigev = nxt_event_engine_signal_find(thr, signo);
+ sigev = nxt_event_engine_signal_find(task, signo);
if (nxt_fast_path(sigev != NULL)) {
- sigev->handler(thr, (void *) (uintptr_t) signo,
+ sigev->handler(task, (void *) (uintptr_t) signo,
(void *) sigev->name);
}
}
@@ -307,70 +311,77 @@ nxt_event_engine_signal_pipe(nxt_thread_t *thr, void *obj, void *data)
} while (n == sizeof(buf));
if (post) {
- nxt_event_engine_post_handler(thr, NULL, NULL);
+ nxt_event_engine_post_handler(task, NULL, NULL);
}
}
static void
-nxt_event_engine_post_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_engine_post_handler(nxt_task_t *task, void *obj, void *data)
{
- nxt_locked_work_queue_move(thr, &thr->engine->work_queue,
- &thr->work_queue.main);
+ nxt_thread_t *thread;
+
+ thread = task->thread;
+
+ nxt_locked_work_queue_move(thread, &thread->engine->work_queue,
+ &thread->work_queue.main);
}
static void
-nxt_event_engine_signal_pipe_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_engine_signal_pipe_error(nxt_task_t *task, void *obj, void *data)
{
- nxt_event_fd_t *ev;
+ nxt_event_engine_t *engine;
- ev = obj;
+ engine = task->thread->engine;
- nxt_log_alert(ev->log, "engine pipe(%FD:%FD) event error",
- thr->engine->pipe->fds[0], thr->engine->pipe->fds[1]);
+ nxt_log(task, NXT_LOG_CRIT, "engine pipe(%FD:%FD) event error",
+ engine->pipe->fds[0], engine->pipe->fds[1]);
- nxt_event_fd_close(thr->engine, &thr->engine->pipe->event);
- nxt_pipe_close(thr->engine->pipe->fds);
+ nxt_event_fd_close(engine, &engine->pipe->event);
+ nxt_pipe_close(engine->pipe->fds);
}
static void
-nxt_event_engine_signal_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_event_engine_signal_handler(nxt_task_t *task, void *obj, void *data)
{
uintptr_t signo;
const nxt_event_sig_t *sigev;
signo = (uintptr_t) obj;
- sigev = nxt_event_engine_signal_find(thr, signo);
+ sigev = nxt_event_engine_signal_find(task, signo);
if (nxt_fast_path(sigev != NULL)) {
- sigev->handler(thr, (void *) (uintptr_t) signo, (void *) sigev->name);
+ sigev->handler(task, (void *) (uintptr_t) signo, (void *) sigev->name);
}
}
static const nxt_event_sig_t *
-nxt_event_engine_signal_find(nxt_thread_t *thr, nxt_uint_t signo)
+nxt_event_engine_signal_find(nxt_task_t *task, nxt_uint_t signo)
{
const nxt_event_sig_t *sigev;
- for (sigev = thr->engine->signals->sigev; sigev->signo != 0; sigev++) {
+ for (sigev = task->thread->engine->signals->sigev;
+ sigev->signo != 0;
+ sigev++)
+ {
if (signo == (nxt_uint_t) sigev->signo) {
return sigev;
}
}
- nxt_log_alert(thr->log, "signal %ui handler not found", signo);
+ nxt_log(task, NXT_LOG_CRIT, "signal %ui handler not found", signo);
return NULL;
}
nxt_int_t
-nxt_event_engine_change(nxt_thread_t *thr, const nxt_event_set_ops_t *event_set,
- nxt_uint_t batch)
+nxt_event_engine_change(nxt_thread_t *thr, nxt_task_t *task,
+ const nxt_event_set_ops_t *event_set, nxt_uint_t batch)
{
nxt_uint_t events;
nxt_event_engine_t *engine;
@@ -389,7 +400,7 @@ nxt_event_engine_change(nxt_thread_t *thr, const nxt_event_set_ops_t *event_set,
* Add to thread main work queue the signal events possibly
* received before the blocking signal processing.
*/
- nxt_event_engine_signal_pipe(thr, &engine->pipe->event, NULL);
+ nxt_event_engine_signal_pipe(task, &engine->pipe->event, NULL);
}
if (engine->pipe != NULL && event_set->enable_post != NULL) {
@@ -399,7 +410,7 @@ nxt_event_engine_change(nxt_thread_t *thr, const nxt_event_set_ops_t *event_set,
*/
nxt_thread_work_queue_add(thr, &thr->work_queue.main,
nxt_event_engine_signal_pipe_close,
- engine->pipe, NULL, &nxt_main_log);
+ &engine->task, engine->pipe, NULL);
engine->pipe = NULL;
}
@@ -415,7 +426,7 @@ nxt_event_engine_change(nxt_thread_t *thr, const nxt_event_set_ops_t *event_set,
engine->event = event_set;
- if (nxt_event_engine_post_init(thr, engine) != NXT_OK) {
+ if (nxt_event_engine_post_init(engine) != NXT_OK) {
return NXT_ERROR;
}
@@ -459,6 +470,7 @@ void
nxt_event_engine_start(nxt_event_engine_t *engine)
{
void *obj, *data;
+ nxt_task_t *task;
nxt_msec_t timeout, now;
nxt_thread_t *thr;
nxt_work_handler_t handler;
@@ -478,25 +490,25 @@ nxt_event_engine_start(nxt_event_engine_t *engine)
for ( ;; ) {
for ( ;; ) {
- handler = nxt_thread_work_queue_pop(thr, &obj, &data, &thr->log);
+ handler = nxt_thread_work_queue_pop(thr, &task, &obj, &data);
if (handler == NULL) {
break;
}
- handler(thr, obj, data);
+ handler(task, obj, data);
thr->log = &nxt_main_log;
}
for ( ;; ) {
- handler = nxt_thread_last_work_queue_pop(thr, &obj, &data,
- &thr->log);
+ handler = nxt_thread_last_work_queue_pop(thr, &task, &obj, &data);
+
if (handler == NULL) {
break;
}
- handler(thr, obj, data);
+ handler(task, obj, data);
thr->log = &nxt_main_log;
}
@@ -508,7 +520,7 @@ nxt_event_engine_start(nxt_event_engine_t *engine)
timeout = nxt_event_timer_find(engine);
- engine->event->poll(thr, engine->event_set, timeout);
+ engine->event->poll(task, engine->event_set, timeout);
/*
* Look up expired timers only if a new zero timer has been
diff --git a/src/nxt_event_engine.h b/src/nxt_event_engine.h
index 0cbfc89d..1ff1399a 100644
--- a/src/nxt_event_engine.h
+++ b/src/nxt_event_engine.h
@@ -23,6 +23,7 @@ struct nxt_event_engine_s {
nxt_event_timers_t timers;
+ nxt_task_t task;
/* The engine ID, the main engine has ID 0. */
uint32_t id;
@@ -44,6 +45,7 @@ struct nxt_event_engine_s {
nxt_event_signals_t *signals;
+ nxt_thread_t *thread;
nxt_fiber_main_t *fibers;
uint8_t shutdown; /* 1 bit */
@@ -61,12 +63,13 @@ NXT_EXPORT nxt_event_engine_t *nxt_event_engine_create(nxt_thread_t *thr,
const nxt_event_set_ops_t *event_set, const nxt_event_sig_t *signals,
nxt_uint_t flags, nxt_uint_t batch);
NXT_EXPORT nxt_int_t nxt_event_engine_change(nxt_thread_t *thr,
- const nxt_event_set_ops_t *event_set, nxt_uint_t batch);
+ nxt_task_t *task, const nxt_event_set_ops_t *event_set, nxt_uint_t batch);
NXT_EXPORT void nxt_event_engine_free(nxt_event_engine_t *engine);
NXT_EXPORT void nxt_event_engine_start(nxt_event_engine_t *engine);
NXT_EXPORT void nxt_event_engine_post(nxt_event_engine_t *engine,
- nxt_work_handler_t handler, void *obj, void *data, nxt_log_t *log);
+ nxt_work_handler_t handler, nxt_task_t *task, void *obj, void *data,
+ nxt_log_t *log);
NXT_EXPORT void nxt_event_engine_signal(nxt_event_engine_t *engine,
nxt_uint_t signo);
diff --git a/src/nxt_event_fd.h b/src/nxt_event_fd.h
index dd8d1c20..20cb7a92 100644
--- a/src/nxt_event_fd.h
+++ b/src/nxt_event_fd.h
@@ -97,6 +97,8 @@ struct nxt_event_fd_s {
int32_t kq_available;
#endif
+ nxt_task_t *task;
+
nxt_work_queue_t *read_work_queue;
nxt_work_handler_t read_handler;
nxt_work_queue_t *write_work_queue;
diff --git a/src/nxt_event_file.h b/src/nxt_event_file.h
index 8426f912..06f1762f 100644
--- a/src/nxt_event_file.h
+++ b/src/nxt_event_file.h
@@ -11,6 +11,7 @@ typedef struct {
void *data;
nxt_file_t *file;
nxt_work_handler_t handler;
+ nxt_task_t *task;
} nxt_event_file_t;
diff --git a/src/nxt_event_set.h b/src/nxt_event_set.h
index 103a8125..01c36ea1 100644
--- a/src/nxt_event_set.h
+++ b/src/nxt_event_set.h
@@ -163,7 +163,7 @@ typedef struct {
nxt_uint_t signo);
/* Poll an event set for new event notifications. */
- void (*poll)(nxt_thread_t *thr,
+ void (*poll)(nxt_task_t *task,
nxt_event_set_t *event_set,
nxt_msec_t timeout);
diff --git a/src/nxt_event_timer.c b/src/nxt_event_timer.c
index 29c225de..4a260705 100644
--- a/src/nxt_event_timer.c
+++ b/src/nxt_event_timer.c
@@ -141,8 +141,8 @@ nxt_event_timer_change(nxt_event_timers_t *timers, nxt_event_timer_t *ev,
void
nxt_event_timer_disable(nxt_event_timer_t *ev)
{
- nxt_log_debug(ev->log, "event timer disable: %D: %d:%M",
- ev->ident, ev->state, ev->time);
+ nxt_debug(ev->task, "event timer disable: %D: %d:%M",
+ ev->ident, ev->state, ev->time);
ev->state = NXT_EVENT_TIMER_DISABLED;
}
@@ -314,7 +314,7 @@ nxt_event_timer_expire(nxt_thread_t *thr, nxt_msec_t now)
ev->state = NXT_EVENT_TIMER_DISABLED;
nxt_thread_work_queue_add(thr, ev->work_queue, ev->handler,
- ev, NULL, ev->log);
+ ev->task, ev, NULL);
}
}
}
diff --git a/src/nxt_event_timer.h b/src/nxt_event_timer.h
index c20c2c17..64fbcbc4 100644
--- a/src/nxt_event_timer.h
+++ b/src/nxt_event_timer.h
@@ -15,11 +15,11 @@
#if (NXT_DEBUG)
#define NXT_EVENT_TIMER { NXT_RBTREE_NODE_INIT, 0, 0, 0, \
- NULL, NULL, NULL, -1 }
+ NULL, NULL, NULL, NULL, -1 }
#else
#define NXT_EVENT_TIMER { NXT_RBTREE_NODE_INIT, 0, 0, 0, \
- NULL, NULL, NULL }
+ NULL, NULL, NULL, NULL }
#endif
@@ -34,6 +34,7 @@ typedef struct {
nxt_work_queue_t *work_queue;
nxt_work_handler_t handler;
+ nxt_task_t *task;
nxt_log_t *log;
#if (NXT_DEBUG)
int32_t ident;
diff --git a/src/nxt_fastcgi_record_parse.c b/src/nxt_fastcgi_record_parse.c
index 66b9d4c3..7d2ce32e 100644
--- a/src/nxt_fastcgi_record_parse.c
+++ b/src/nxt_fastcgi_record_parse.c
@@ -17,13 +17,13 @@ static nxt_int_t nxt_fastcgi_buffer(nxt_fastcgi_parse_t *fp, nxt_buf_t ***tail,
void
-nxt_fastcgi_record_parse(nxt_fastcgi_parse_t *fp, nxt_buf_t *in)
+nxt_fastcgi_record_parse(nxt_task_t *task, nxt_fastcgi_parse_t *fp,
+ nxt_buf_t *in)
{
u_char ch;
nxt_int_t ret, stream;
nxt_buf_t *b, *nb, **tail[2];
const char *msg;
- nxt_thread_t *thr;
enum {
sw_fastcgi_version = 0,
sw_fastcgi_type,
@@ -208,9 +208,9 @@ nxt_fastcgi_record_parse(nxt_fastcgi_parse_t *fp, nxt_buf_t *in)
if (b->retain == 0) {
/* No record data was found in a buffer. */
- thr = nxt_thread();
- nxt_thread_current_work_queue_add(thr, b->completion_handler,
- b, b->parent, thr->log);
+ nxt_thread_current_work_queue_add(task->thread,
+ b->completion_handler,
+ task, b, b->parent);
}
next:
diff --git a/src/nxt_fastcgi_source.c b/src/nxt_fastcgi_source.c
index 14c51d6f..d655fca8 100644
--- a/src/nxt_fastcgi_source.c
+++ b/src/nxt_fastcgi_source.c
@@ -49,16 +49,17 @@ static nxt_buf_t *nxt_fastcgi_request_create(nxt_fastcgi_source_t *fs);
static nxt_int_t nxt_fastcgi_next_param(nxt_fastcgi_source_t *fs,
nxt_fastcgi_param_t *param);
-static void nxt_fastcgi_source_record_filter(nxt_thread_t *thr, void *obj,
+static void nxt_fastcgi_source_record_filter(nxt_task_t *task, void *obj,
void *data);
-static void nxt_fastcgi_source_record_error(nxt_thread_t *thr, void *obj,
+static void nxt_fastcgi_source_record_error(nxt_task_t *task, void *obj,
void *data);
-static void nxt_fastcgi_source_header_filter(nxt_thread_t *thr, void *obj,
+static void nxt_fastcgi_source_header_filter(nxt_task_t *task, void *obj,
void *data);
-static void nxt_fastcgi_source_sync_buffer(nxt_thread_t *thr,
+static void nxt_fastcgi_source_sync_buffer(nxt_task_t *task,
nxt_fastcgi_source_t *fs, nxt_buf_t *b);
-static nxt_int_t nxt_fastcgi_source_header_process(nxt_fastcgi_source_t *fs);
+static nxt_int_t nxt_fastcgi_source_header_process(nxt_task_t *task,
+ nxt_fastcgi_source_t *fs);
static nxt_int_t nxt_fastcgi_source_status(nxt_upstream_source_t *us,
nxt_name_value_t *nv);
static nxt_int_t nxt_fastcgi_source_content_length(nxt_upstream_source_t *us,
@@ -66,11 +67,12 @@ static nxt_int_t nxt_fastcgi_source_content_length(nxt_upstream_source_t *us,
static void nxt_fastcgi_source_header_ready(nxt_fastcgi_source_t *fs,
nxt_buf_t *b);
-static void nxt_fastcgi_source_body_filter(nxt_thread_t *thr, void *obj,
+static void nxt_fastcgi_source_body_filter(nxt_task_t *task, void *obj,
void *data);
static nxt_buf_t *nxt_fastcgi_source_last_buf(nxt_fastcgi_parse_t *fp);
-static void nxt_fastcgi_source_error(nxt_stream_source_t *stream);
-static void nxt_fastcgi_source_fail(nxt_fastcgi_source_t *fs);
+static void nxt_fastcgi_source_error(nxt_task_t *task,
+ nxt_stream_source_t *stream);
+static void nxt_fastcgi_source_fail(nxt_task_t *task, nxt_fastcgi_source_t *fs);
/*
@@ -117,7 +119,7 @@ static const uint8_t nxt_fastcgi_stdin_record[] = {
void
-nxt_fastcgi_source_handler(nxt_upstream_source_t *us,
+nxt_fastcgi_source_handler(nxt_task_t *task, nxt_upstream_source_t *us,
nxt_fastcgi_source_request_create_t request_create)
{
nxt_stream_source_t *stream;
@@ -181,13 +183,13 @@ nxt_fastcgi_source_handler(nxt_upstream_source_t *us,
nxt_memzero(&fs->u.header, sizeof(nxt_http_split_header_parse_t));
fs->u.header.mem_pool = fs->upstream->buffers.mem_pool;
- nxt_stream_source_connect(stream);
+ nxt_stream_source_connect(task, stream);
return;
}
fail:
- nxt_fastcgi_source_fail(fs);
+ nxt_fastcgi_source_fail(task, fs);
}
@@ -383,7 +385,7 @@ nxt_fastcgi_next_param(nxt_fastcgi_source_t *fs, nxt_fastcgi_param_t *param)
static void
-nxt_fastcgi_source_record_filter(nxt_thread_t *thr, void *obj, void *data)
+nxt_fastcgi_source_record_filter(nxt_task_t *task, void *obj, void *data)
{
size_t size;
u_char *p;
@@ -394,18 +396,18 @@ nxt_fastcgi_source_record_filter(nxt_thread_t *thr, void *obj, void *data)
fsr = obj;
in = data;
- nxt_log_debug(thr->log, "fastcgi source record filter");
+ nxt_debug(task, "fastcgi source record filter");
if (nxt_slow_path(fsr->parse.done)) {
return;
}
- nxt_fastcgi_record_parse(&fsr->parse, in);
+ nxt_fastcgi_record_parse(task, &fsr->parse, in);
fs = nxt_container_of(fsr, nxt_fastcgi_source_t, record);
if (fsr->parse.error) {
- nxt_fastcgi_source_fail(fs);
+ nxt_fastcgi_source_fail(task, fs);
return;
}
@@ -413,8 +415,9 @@ nxt_fastcgi_source_record_filter(nxt_thread_t *thr, void *obj, void *data)
/*
* Output all parsed before a FastCGI record error and close upstream.
*/
- nxt_thread_current_work_queue_add(thr, nxt_fastcgi_source_record_error,
- fs, NULL, thr->log);
+ nxt_thread_current_work_queue_add(task->thread,
+ nxt_fastcgi_source_record_error,
+ task, fs, NULL);
}
/* Log FastCGI stderr output. */
@@ -430,36 +433,36 @@ nxt_fastcgi_source_record_filter(nxt_thread_t *thr, void *obj, void *data)
size = (p + 1) - b->mem.pos;
if (size != 0) {
- nxt_log_error(NXT_LOG_ERR, thr->log,
- "upstream sent in FastCGI stderr: \"%*s\"",
- size, b->mem.pos);
+ nxt_log(task, NXT_LOG_ERR,
+ "upstream sent in FastCGI stderr: \"%*s\"",
+ size, b->mem.pos);
}
- b->completion_handler(thr, b, b->parent);
+ b->completion_handler(task, b, b->parent);
}
/* Process FastCGI stdout output. */
if (fsr->parse.out[0] != NULL) {
- nxt_source_filter(thr, fs->upstream->work_queue, &fsr->next,
- fsr->parse.out[0]);
+ nxt_source_filter(task->thread, fs->upstream->work_queue, task,
+ &fsr->next, fsr->parse.out[0]);
}
}
static void
-nxt_fastcgi_source_record_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_fastcgi_source_record_error(nxt_task_t *task, void *obj, void *data)
{
nxt_fastcgi_source_t *fs;
fs = obj;
- nxt_fastcgi_source_fail(fs);
+ nxt_fastcgi_source_fail(task, fs);
}
static void
-nxt_fastcgi_source_header_filter(nxt_thread_t *thr, void *obj, void *data)
+nxt_fastcgi_source_header_filter(nxt_task_t *task, void *obj, void *data)
{
nxt_int_t ret;
nxt_buf_t *b;
@@ -469,10 +472,10 @@ nxt_fastcgi_source_header_filter(nxt_thread_t *thr, void *obj, void *data)
b = data;
do {
- nxt_log_debug(thr->log, "fastcgi source header filter");
+ nxt_debug(task, "fastcgi source header filter");
if (nxt_slow_path(nxt_buf_is_sync(b))) {
- nxt_fastcgi_source_sync_buffer(thr, fs, b);
+ nxt_fastcgi_source_sync_buffer(task, fs, b);
return;
}
@@ -483,7 +486,7 @@ nxt_fastcgi_source_header_filter(nxt_thread_t *thr, void *obj, void *data)
break;
}
- ret = nxt_fastcgi_source_header_process(fs);
+ ret = nxt_fastcgi_source_header_process(task, fs);
if (nxt_slow_path(ret != NXT_OK)) {
break;
@@ -491,7 +494,7 @@ nxt_fastcgi_source_header_filter(nxt_thread_t *thr, void *obj, void *data)
}
if (nxt_fast_path(ret == NXT_DONE)) {
- nxt_log_debug(thr->log, "fastcgi source header done");
+ nxt_debug(task, "fastcgi source header done");
nxt_fastcgi_source_header_ready(fs, b);
return;
}
@@ -500,16 +503,16 @@ nxt_fastcgi_source_header_filter(nxt_thread_t *thr, void *obj, void *data)
if (ret != NXT_ERROR) {
/* n == NXT_DECLINED: "\r" is not followed by "\n" */
- nxt_log_error(NXT_LOG_ERR, thr->log,
- "upstream sent invalid header line: \"%*s\\r...\"",
- fs->u.header.parse.header_end
- - fs->u.header.parse.header_name_start,
- fs->u.header.parse.header_name_start);
+ nxt_log(task, NXT_LOG_ERR,
+ "upstream sent invalid header line: \"%*s\\r...\"",
+ fs->u.header.parse.header_end
+ - fs->u.header.parse.header_name_start,
+ fs->u.header.parse.header_name_start);
}
/* ret == NXT_ERROR */
- nxt_fastcgi_source_fail(fs);
+ nxt_fastcgi_source_fail(task, fs);
return;
}
@@ -520,45 +523,41 @@ nxt_fastcgi_source_header_filter(nxt_thread_t *thr, void *obj, void *data)
static void
-nxt_fastcgi_source_sync_buffer(nxt_thread_t *thr, nxt_fastcgi_source_t *fs,
+nxt_fastcgi_source_sync_buffer(nxt_task_t *task, nxt_fastcgi_source_t *fs,
nxt_buf_t *b)
{
if (nxt_buf_is_last(b)) {
- nxt_log_error(NXT_LOG_ERR, thr->log,
- "upstream closed prematurely connection");
+ nxt_log(task, NXT_LOG_ERR, "upstream closed prematurely connection");
} else {
- nxt_log_error(NXT_LOG_ERR, thr->log, "%ui buffers %uz each are not "
- "enough to process upstream response header",
- fs->upstream->buffers.max,
- fs->upstream->buffers.size);
+ nxt_log(task, NXT_LOG_ERR, "%ui buffers %uz each are not "
+ "enough to process upstream response header",
+ fs->upstream->buffers.max, fs->upstream->buffers.size);
}
/* The stream source sends only the last and the nobuf sync buffer. */
- nxt_fastcgi_source_fail(fs);
+ nxt_fastcgi_source_fail(task, fs);
}
static nxt_int_t
-nxt_fastcgi_source_header_process(nxt_fastcgi_source_t *fs)
+nxt_fastcgi_source_header_process(nxt_task_t *task, nxt_fastcgi_source_t *fs)
{
size_t len;
- nxt_thread_t *thr;
nxt_name_value_t *nv;
nxt_lvlhsh_query_t lhq;
nxt_http_header_parse_t *hp;
nxt_upstream_name_value_t *unv;
- thr = nxt_thread();
hp = &fs->u.header.parse;
len = hp->header_name_end - hp->header_name_start;
if (len > 255) {
- nxt_log_error(NXT_LOG_INFO, thr->log,
- "upstream sent too long header field name: \"%*s\"",
- len, hp->header_name_start);
+ nxt_log(task, NXT_LOG_INFO,
+ "upstream sent too long header field name: \"%*s\"",
+ len, hp->header_name_start);
return NXT_ERROR;
}
@@ -574,8 +573,8 @@ nxt_fastcgi_source_header_process(nxt_fastcgi_source_t *fs)
nv->value_len = hp->header_end - hp->header_start;
nv->value_start = hp->header_start;
- nxt_log_debug(thr->log, "http header: \"%*s: %*s\"",
- nv->name_len, nv->name_start, nv->value_len, nv->value_start);
+ nxt_debug(task, "http header: \"%*s: %*s\"",
+ nv->name_len, nv->name_start, nv->value_len, nv->value_start);
lhq.key_hash = nv->hash;
lhq.key.len = nv->name_len;
@@ -682,7 +681,7 @@ nxt_fastcgi_source_header_ready(nxt_fastcgi_source_t *fs, nxt_buf_t *b)
*/
static void
-nxt_fastcgi_source_body_filter(nxt_thread_t *thr, void *obj, void *data)
+nxt_fastcgi_source_body_filter(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b, *in;
nxt_fastcgi_source_t *fs;
@@ -690,7 +689,7 @@ nxt_fastcgi_source_body_filter(nxt_thread_t *thr, void *obj, void *data)
fs = obj;
in = data;
- nxt_log_debug(thr->log, "fastcgi source body filter");
+ nxt_debug(task, "fastcgi source body filter");
for (b = in; b != NULL; b = b->next) {
@@ -701,7 +700,8 @@ nxt_fastcgi_source_body_filter(nxt_thread_t *thr, void *obj, void *data)
}
if (fs->next != NULL) {
- nxt_source_filter(thr, fs->upstream->work_queue, fs->next, in);
+ nxt_source_filter(task->thread, fs->upstream->work_queue, task,
+ fs->next, in);
return;
}
@@ -729,7 +729,7 @@ nxt_fastcgi_source_last_buf(nxt_fastcgi_parse_t *fp)
static void
-nxt_fastcgi_source_error(nxt_stream_source_t *stream)
+nxt_fastcgi_source_error(nxt_task_t *task, nxt_stream_source_t *stream)
{
nxt_fastcgi_source_t *fs;
@@ -737,20 +737,16 @@ nxt_fastcgi_source_error(nxt_stream_source_t *stream)
fs = stream->upstream->protocol_source;
- nxt_fastcgi_source_fail(fs);
+ nxt_fastcgi_source_fail(task, fs);
}
static void
-nxt_fastcgi_source_fail(nxt_fastcgi_source_t *fs)
+nxt_fastcgi_source_fail(nxt_task_t *task, nxt_fastcgi_source_t *fs)
{
- nxt_thread_t *thr;
-
- thr = nxt_thread();
-
- nxt_log_debug(thr->log, "fastcgi source fail");
+ nxt_debug(task, "fastcgi source fail");
/* TODO: fail, next upstream, or bad gateway */
- fs->upstream->state->error_handler(thr, fs, NULL);
+ fs->upstream->state->error_handler(task, fs, NULL);
}
diff --git a/src/nxt_fastcgi_source.h b/src/nxt_fastcgi_source.h
index e02cc5f4..0bb7692a 100644
--- a/src/nxt_fastcgi_source.h
+++ b/src/nxt_fastcgi_source.h
@@ -82,11 +82,13 @@ struct nxt_fastcgi_source_s {
};
-NXT_EXPORT void nxt_fastcgi_source_handler(nxt_upstream_source_t *us,
+NXT_EXPORT void nxt_fastcgi_source_handler(nxt_task_t *task,
+ nxt_upstream_source_t *us,
nxt_fastcgi_source_request_create_t request_create);
NXT_EXPORT nxt_int_t nxt_fastcgi_source_hash_create(nxt_mem_pool_t *mp,
nxt_lvlhsh_t *lh);
-void nxt_fastcgi_record_parse(nxt_fastcgi_parse_t *fp, nxt_buf_t *in);
+void nxt_fastcgi_record_parse(nxt_task_t *task, nxt_fastcgi_parse_t *fp,
+ nxt_buf_t *in);
#endif /* _NXT_FASTCGI_SOURCE_H_INCLUDED_ */
diff --git a/src/nxt_fiber.c b/src/nxt_fiber.c
index 74473f85..a7b89402 100644
--- a/src/nxt_fiber.c
+++ b/src/nxt_fiber.c
@@ -7,19 +7,17 @@
#include <nxt_main.h>
-static char *nxt_fiber_create_stack(nxt_fiber_t *fib);
+static char *nxt_fiber_create_stack(nxt_task_t *task, nxt_fiber_t *fib);
static void nxt_fiber_switch_stack(nxt_fiber_t *fib, jmp_buf *parent);
-static void nxt_fiber_switch_handler(nxt_thread_t *thr, void *obj,
- void *data);
-static void nxt_fiber_switch(nxt_thread_t *thr, nxt_fiber_t *fib);
-static void nxt_fiber_timer_handler(nxt_thread_t *thr, void *obj,
- void *data);
+static void nxt_fiber_switch_handler(nxt_task_t *task, void *obj, void *data);
+static void nxt_fiber_switch(nxt_task_t *task, nxt_fiber_t *fib);
+static void nxt_fiber_timer_handler(nxt_task_t *task, void *obj, void *data);
#define \
-nxt_fiber_enqueue(thr, fib) \
+nxt_fiber_enqueue(thr, task, fib) \
nxt_thread_work_queue_add(thr, &(thr)->work_queue.main, \
- nxt_fiber_switch_handler, fib, NULL, thr->log)
+ nxt_fiber_switch_handler, task, fib, NULL)
nxt_fiber_main_t *
@@ -32,6 +30,7 @@ nxt_fiber_main_create(nxt_event_engine_t *engine)
return NULL;
}
+ fm->engine = engine;
fm->stack_size = 512 * 1024 - nxt_pagesize;
fm->idle = NULL;
@@ -67,8 +66,14 @@ nxt_fiber_create(nxt_fiber_start_t start, void *data, size_t stack)
fib->data = data;
fib->main = fm;
- nxt_log_debug(thr->log, "fiber create cached: %PF", fib->fid);
- nxt_fiber_enqueue(thr, fib);
+ fib->task.thread = thr;
+ fib->task.log = thr->log;
+ fib->task.ident = nxt_task_next_ident();
+
+ nxt_debug(&fib->task, "fiber create cached: %PF", fib->fid);
+
+ nxt_fiber_enqueue(thr, &fm->engine->task, fib);
+
return NXT_OK;
}
@@ -85,7 +90,11 @@ nxt_fiber_create(nxt_fiber_start_t start, void *data, size_t stack)
fib->stack_size = fm->stack_size;
fib->main = fm;
- fib->stack = nxt_fiber_create_stack(fib);
+ fib->task.thread = thr;
+ fib->task.log = thr->log;
+ fib->task.ident = nxt_task_next_ident();
+
+ fib->stack = nxt_fiber_create_stack(&fib->task, fib);
if (nxt_fast_path(fib->stack != NULL)) {
@@ -113,7 +122,7 @@ nxt_fiber_create(nxt_fiber_start_t start, void *data, size_t stack)
#if (NXT_LINUX)
static char *
-nxt_fiber_create_stack(nxt_fiber_t *fib)
+nxt_fiber_create_stack(nxt_task_t *task, nxt_fiber_t *fib)
{
char *s;
size_t size;
@@ -124,21 +133,24 @@ nxt_fiber_create_stack(nxt_fiber_t *fib)
MAP_PRIVATE | MAP_ANON | MAP_GROWSDOWN, -1, 0);
if (nxt_slow_path(s == MAP_FAILED)) {
- nxt_thread_log_alert("fiber stack "
- "mmap(%uz, MAP_PRIVATE|MAP_ANON|MAP_GROWSDOWN) failed %E",
- size, nxt_errno);
+ nxt_log(task, NXT_LOG_CRIT, "fiber stack "
+ "mmap(%uz, MAP_PRIVATE|MAP_ANON|MAP_GROWSDOWN) failed %E",
+ size, nxt_errno);
+
return NULL;
}
if (nxt_slow_path(mprotect(s, nxt_pagesize, PROT_NONE) != 0)) {
- nxt_thread_log_alert("fiber stack mprotect(%uz, PROT_NONE) failed %E",
- size, nxt_errno);
+ nxt_log(task, NXT_LOG_CRIT,
+ "fiber stack mprotect(%uz, PROT_NONE) failed %E",
+ size, nxt_errno);
+
return NULL;
}
s += nxt_pagesize;
- nxt_thread_log_debug("fiber stack mmap: %p", s);
+ nxt_debug(task, "fiber stack mmap: %p", s);
return s;
}
@@ -146,7 +158,7 @@ nxt_fiber_create_stack(nxt_fiber_t *fib)
#else /* Generic version. */
static char *
-nxt_fiber_create_stack(nxt_fiber_t *fib)
+nxt_fiber_create_stack(nxt_task_t *task, nxt_fiber_t *fib)
{
char *s;
size_t size;
@@ -156,21 +168,24 @@ nxt_fiber_create_stack(nxt_fiber_t *fib)
s = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
if (nxt_slow_path(s == MAP_FAILED)) {
- nxt_thread_log_alert("fiber stack "
- "mmap(%uz, MAP_PRIVATE|MAP_ANON) failed %E",
- size, nxt_errno);
+ nxt_log(task, NXT_LOG_CRIT,
+ "fiber stack mmap(%uz, MAP_PRIVATE|MAP_ANON) failed %E",
+ size, nxt_errno);
+
return NULL;
}
if (nxt_slow_path(mprotect(s, nxt_pagesize, PROT_NONE) != 0)) {
- nxt_thread_log_alert("fiber stack mprotect(%uz, PROT_NONE) failed %E",
- size, nxt_errno);
+ nxt_log(task, NXT_LOG_CRIT,
+ "fiber stack mprotect(%uz, PROT_NONE) failed %E",
+ size, nxt_errno);
+
return NULL;
}
s += nxt_pagesize;
- nxt_thread_log_debug("fiber stack mmap: %p", s);
+ nxt_debug(task, "fiber stack mmap: %p", s);
return s;
}
@@ -194,10 +209,10 @@ nxt_fiber_switch_stack(nxt_fiber_t *fib, jmp_buf *parent)
{
ucontext_t uc;
- nxt_thread_log_debug("fiber switch to stack: %p", fib->stack);
+ nxt_debug(&fib->task, "fiber switch to stack: %p", fib->stack);
if (nxt_slow_path(getcontext(&uc) != 0)) {
- nxt_thread_log_alert("getcontext() failed");
+ nxt_log(&fib->task, NXT_LOG_CRIT, "getcontext() failed");
return;
}
@@ -213,35 +228,38 @@ nxt_fiber_switch_stack(nxt_fiber_t *fib, jmp_buf *parent)
setcontext(&uc);
- nxt_thread_log_alert("setcontext() failed");
+ nxt_log(&fib->task, NXT_LOG_CRIT, "setcontext() failed");
}
static void
nxt_fiber_trampoline(uint32_t fh, uint32_t fl, uint32_t ph, uint32_t pl)
{
- jmp_buf *parent;
- nxt_fiber_t *fib;
- nxt_thread_t *thr;
+ jmp_buf *parent;
+ nxt_task_t *task;
+ nxt_fiber_t *fib;
fib = (nxt_fiber_t *) (((uintptr_t) fh << 32) + fl);
parent = (jmp_buf *) (((uintptr_t) ph << 32) + pl);
- thr = nxt_thread();
+ task = &fib->task;
if (_setjmp(fib->jmp) == 0) {
- nxt_log_debug(thr->log, "fiber return to parent stack");
+ nxt_debug(task, "fiber return to parent stack");
+
+ nxt_fiber_enqueue(task->thread, task, fib);
- nxt_fiber_enqueue(thr, fib);
_longjmp(*parent, 1);
+
nxt_unreachable();
}
- nxt_log_debug(thr->log, "fiber start");
+ nxt_debug(task, "fiber start");
fib->start(fib->data);
- nxt_fiber_exit(&fib->main->fiber, NULL);
+ nxt_fiber_exit(task, &fib->main->fiber, NULL);
+
nxt_unreachable();
}
@@ -257,10 +275,10 @@ nxt_fiber_switch_stack(nxt_fiber_t *fib, jmp_buf *parent)
{
ucontext_t uc;
- nxt_thread_log_debug("fiber switch to stack: %p", fib->stack);
+ nxt_debug(&fib->task, "fiber switch to stack: %p", fib->stack);
if (nxt_slow_path(getcontext(&uc) != 0)) {
- nxt_thread_log_alert("getcontext() failed");
+ nxt_log(&fib->task, NXT_LOG_CRIT, "getcontext() failed");
return;
}
@@ -275,7 +293,7 @@ nxt_fiber_switch_stack(nxt_fiber_t *fib, jmp_buf *parent)
#if !(NXT_SOLARIS)
/* Solaris declares setcontext() as __NORETURN. */
- nxt_thread_log_alert("setcontext() failed");
+ nxt_log(&fib->task, NXT_LOG_CRIT, "setcontext() failed");
#endif
}
@@ -283,23 +301,26 @@ nxt_fiber_switch_stack(nxt_fiber_t *fib, jmp_buf *parent)
static void
nxt_fiber_trampoline(nxt_fiber_t *fib, jmp_buf *parent)
{
- nxt_thread_t *thr;
+ nxt_task_t *task;
- thr = nxt_thread();
+ task = &fib->task;
if (_setjmp(fib->jmp) == 0) {
- nxt_log_debug(thr->log, "fiber return to parent stack");
+ nxt_debug(task, "fiber return to parent stack");
+
+ nxt_fiber_enqueue(task->thread, task, fib);
- nxt_fiber_enqueue(thr, fib);
_longjmp(*parent, 1);
+
nxt_unreachable();
}
- nxt_log_debug(thr->log, "fiber start");
+ nxt_debug(task, "fiber start");
fib->start(fib->data);
- nxt_fiber_exit(&fib->main->fiber, NULL);
+ nxt_fiber_exit(task, &fib->main->fiber, NULL);
+
nxt_unreachable();
}
@@ -311,24 +332,26 @@ nxt_fiber_trampoline(nxt_fiber_t *fib, jmp_buf *parent)
static void
-nxt_fiber_switch_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_fiber_switch_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_fiber_t *fib;
fib = obj;
- nxt_fiber_switch(thr, fib);
+ nxt_fiber_switch(task, fib);
nxt_unreachable();
}
static void
-nxt_fiber_switch(nxt_thread_t *thr, nxt_fiber_t *fib)
+nxt_fiber_switch(nxt_task_t *task, nxt_fiber_t *fib)
{
- nxt_log_debug(thr->log, "fiber switch: %PF", fib->fid);
+ nxt_debug(task, "fiber switch: %PF", fib->fid);
+
+ task->thread->fiber = fib;
- thr->fiber = fib;
_longjmp(fib->jmp, 1);
+
nxt_unreachable();
}
@@ -341,106 +364,106 @@ nxt_fiber_self(nxt_thread_t *thr)
void
-nxt_fiber_yield(void)
+nxt_fiber_yield(nxt_task_t *task)
{
- nxt_fiber_t *fib;
- nxt_thread_t *thr;
+ nxt_fiber_t *fib;
- thr = nxt_thread();
- fib = thr->fiber;
+ fib = task->thread->fiber;
if (_setjmp(fib->jmp) == 0) {
- nxt_log_debug(thr->log, "fiber yield");
+ nxt_debug(task, "fiber yield");
+
+ nxt_fiber_enqueue(task->thread, &fib->main->engine->task, fib);
+
+ nxt_fiber_switch(task, &fib->main->fiber);
- nxt_fiber_enqueue(thr, fib);
- nxt_fiber_switch(thr, &fib->main->fiber);
nxt_unreachable();
}
- nxt_log_debug(thr->log, "fiber yield return");
+ nxt_debug(task, "fiber yield return");
}
void
-nxt_fiber_sleep(nxt_msec_t timeout)
+nxt_fiber_sleep(nxt_task_t *task, nxt_msec_t timeout)
{
- nxt_fiber_t *fib;
- nxt_thread_t *thr;
+ nxt_fiber_t *fib;
- thr = nxt_thread();
- fib = thr->fiber;
+ fib = task->thread->fiber;
- fib->timer.work_queue = &thr->work_queue.main;
+ fib->timer.work_queue = &task->thread->work_queue.main;
fib->timer.handler = nxt_fiber_timer_handler;
fib->timer.log = &nxt_main_log;
- nxt_event_timer_add(thr->engine, &fib->timer, timeout);
+ task = &fib->task;
+
+ nxt_event_timer_add(task->thread->engine, &fib->timer, timeout);
if (_setjmp(fib->jmp) == 0) {
- nxt_log_debug(thr->log, "fiber sleep: %T", timeout);
+ nxt_debug(task, "fiber sleep: %T", timeout);
+
+ nxt_fiber_switch(task, &fib->main->fiber);
- nxt_fiber_switch(thr, &fib->main->fiber);
nxt_unreachable();
}
- nxt_log_debug(thr->log, "fiber sleep return");
+ nxt_debug(task, "fiber sleep return");
}
static void
-nxt_fiber_timer_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_fiber_timer_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_fiber_t *fib;
nxt_event_timer_t *ev;
ev = obj;
- nxt_log_debug(thr->log, "fiber timer handler");
+ nxt_debug(task, "fiber timer handler");
fib = nxt_event_timer_data(ev, nxt_fiber_t, timer);
- nxt_fiber_switch(thr, fib);
+ nxt_fiber_switch(task, fib);
+
nxt_unreachable();
}
void
-nxt_fiber_wait(void)
+nxt_fiber_wait(nxt_task_t *task)
{
- nxt_fiber_t *fib;
- nxt_thread_t *thr;
+ nxt_fiber_t *fib;
- thr = nxt_thread();
- fib = thr->fiber;
+ fib = task->thread->fiber;
if (_setjmp(fib->jmp) == 0) {
- nxt_log_debug(thr->log, "fiber wait");
+ nxt_debug(task, "fiber wait");
+
+ nxt_fiber_switch(task, &fib->main->fiber);
- nxt_fiber_switch(thr, &fib->main->fiber);
nxt_unreachable();
}
- nxt_log_debug(thr->log, "fiber wait return");
+ nxt_debug(task, "fiber wait return");
}
void
-nxt_fiber_exit(nxt_fiber_t *next, void *data)
+nxt_fiber_exit(nxt_task_t *task, nxt_fiber_t *next, void *data)
{
- nxt_fiber_t *fib;
- nxt_thread_t *thr;
+ nxt_fiber_t *fib;
- thr = nxt_thread();
- fib = thr->fiber;
+ fib = task->thread->fiber;
- nxt_log_debug(thr->log, "fiber exit");
+ nxt_debug(task, "fiber exit");
/* TODO: limit idle fibers. */
fib->next = fib->main->idle;
fib->main->idle = fib;
- nxt_fiber_switch(thr, next);
+ nxt_fiber_switch(task, next);
+
nxt_unreachable();
}
diff --git a/src/nxt_fiber.h b/src/nxt_fiber.h
index 7d66612f..8e043b78 100644
--- a/src/nxt_fiber.h
+++ b/src/nxt_fiber.h
@@ -27,6 +27,8 @@ struct nxt_fiber_s {
size_t stack_size;
nxt_err_t err;
+ nxt_task_t task;
+
nxt_fiber_main_t *main;
nxt_fiber_t *next;
@@ -37,6 +39,7 @@ struct nxt_fiber_s {
struct nxt_fiber_main_s {
nxt_fiber_t fiber;
nxt_fiber_t *idle;
+ nxt_event_engine_t *engine;
size_t stack_size;
nxt_fid_t fid;
};
@@ -44,10 +47,10 @@ struct nxt_fiber_main_s {
nxt_fiber_main_t *nxt_fiber_main_create(nxt_event_engine_t *engine);
nxt_int_t nxt_fiber_create(nxt_fiber_start_t start, void *data, size_t stack);
-void nxt_fiber_yield(void);
-void nxt_fiber_sleep(nxt_msec_t timeout);
-void nxt_fiber_wait(void);
-void nxt_fiber_exit(nxt_fiber_t *next, void *data);
+void nxt_fiber_yield(nxt_task_t *task);
+void nxt_fiber_sleep(nxt_task_t *task, nxt_msec_t timeout);
+void nxt_fiber_wait(nxt_task_t *task);
+void nxt_fiber_exit(nxt_task_t *task, nxt_fiber_t *next, void *data);
NXT_EXPORT nxt_fiber_t *nxt_fiber_self(nxt_thread_t *thr);
diff --git a/src/nxt_freebsd_sendfile.c b/src/nxt_freebsd_sendfile.c
index 9cc05c0f..4a61d60f 100644
--- a/src/nxt_freebsd_sendfile.c
+++ b/src/nxt_freebsd_sendfile.c
@@ -50,7 +50,7 @@ nxt_freebsd_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b,
sb.size = 0;
sb.limit = limit;
- nhd = nxt_sendbuf_mem_coalesce(&sb);
+ nhd = nxt_sendbuf_mem_coalesce(c->socket.task, &sb);
if (nhd == 0 && sb.sync) {
return 0;
@@ -70,7 +70,7 @@ nxt_freebsd_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b,
sb.iobuf = tr;
- ntr = nxt_sendbuf_mem_coalesce(&sb);
+ ntr = nxt_sendbuf_mem_coalesce(c->socket.task, &sb);
/*
* Disposal of surplus kernel operations
diff --git a/src/nxt_http_chunk_parse.c b/src/nxt_http_chunk_parse.c
index c0402605..1c9cd190 100644
--- a/src/nxt_http_chunk_parse.c
+++ b/src/nxt_http_chunk_parse.c
@@ -22,12 +22,12 @@ static nxt_int_t nxt_http_chunk_buffer(nxt_http_chunk_parse_t *hcp,
nxt_buf_t *
-nxt_http_chunk_parse(nxt_http_chunk_parse_t *hcp, nxt_buf_t *in)
+nxt_http_chunk_parse(nxt_task_t *task, nxt_http_chunk_parse_t *hcp,
+ nxt_buf_t *in)
{
u_char c, ch;
nxt_int_t ret;
nxt_buf_t *b, *out, *nb, **tail;
- nxt_thread_t *thr;
enum {
sw_start = 0,
sw_chunk_size,
@@ -168,9 +168,9 @@ nxt_http_chunk_parse(nxt_http_chunk_parse_t *hcp, nxt_buf_t *in)
if (b->retain == 0) {
/* No chunk data was found in a buffer. */
- thr = nxt_thread();
- nxt_thread_current_work_queue_add(thr, b->completion_handler,
- b, b->parent, thr->log);
+ nxt_thread_current_work_queue_add(task->thread,
+ b->completion_handler,
+ task, b, b->parent);
}
diff --git a/src/nxt_http_parse.h b/src/nxt_http_parse.h
index e61aa16c..c62cde71 100644
--- a/src/nxt_http_parse.h
+++ b/src/nxt_http_parse.h
@@ -72,8 +72,8 @@ typedef struct {
} nxt_http_chunk_parse_t;
-NXT_EXPORT nxt_buf_t *nxt_http_chunk_parse(nxt_http_chunk_parse_t *hcp,
- nxt_buf_t *in);
+NXT_EXPORT nxt_buf_t *nxt_http_chunk_parse(nxt_task_t *task,
+ nxt_http_chunk_parse_t *hcp, nxt_buf_t *in);
#endif /* _NXT_HTTP_PARSE_H_INCLUDED_ */
diff --git a/src/nxt_http_source.c b/src/nxt_http_source.c
index 045d585b..10c5527b 100644
--- a/src/nxt_http_source.c
+++ b/src/nxt_http_source.c
@@ -15,9 +15,9 @@ typedef struct {
static nxt_buf_t *nxt_http_source_request_create(nxt_http_source_t *hs);
-static void nxt_http_source_status_filter(nxt_thread_t *thr, void *obj,
+static void nxt_http_source_status_filter(nxt_task_t *task, void *obj,
void *data);
-static void nxt_http_source_header_filter(nxt_thread_t *thr, void *obj,
+static void nxt_http_source_header_filter(nxt_task_t *task, void *obj,
void *data);
static nxt_int_t nxt_http_source_header_line_process(nxt_http_source_t *hs);
@@ -26,24 +26,25 @@ static nxt_int_t nxt_http_source_content_length(nxt_upstream_source_t *us,
static nxt_int_t nxt_http_source_transfer_encoding(nxt_upstream_source_t *us,
nxt_name_value_t *nv);
-static void nxt_http_source_header_ready(nxt_http_source_t *hs,
- nxt_buf_t *rest);
-static void nxt_http_source_chunk_filter(nxt_thread_t *thr, void *obj,
+static void nxt_http_source_header_ready(nxt_task_t *task,
+ nxt_http_source_t *hs, nxt_buf_t *rest);
+static void nxt_http_source_chunk_filter(nxt_task_t *task, void *obj,
void *data);
-static void nxt_http_source_chunk_error(nxt_thread_t *thr, void *obj,
+static void nxt_http_source_chunk_error(nxt_task_t *task, void *obj,
void *data);
-static void nxt_http_source_body_filter(nxt_thread_t *thr, void *obj,
+static void nxt_http_source_body_filter(nxt_task_t *task, void *obj,
void *data);
-static void nxt_http_source_sync_buffer(nxt_thread_t *thr,
- nxt_http_source_t *hs, nxt_buf_t *b);
-static void nxt_http_source_error(nxt_stream_source_t *stream);
-static void nxt_http_source_fail(nxt_http_source_t *hs);
+static void nxt_http_source_sync_buffer(nxt_task_t *task, nxt_http_source_t *hs,
+ nxt_buf_t *b);
+static void nxt_http_source_error(nxt_task_t *task,
+ nxt_stream_source_t *stream);
+static void nxt_http_source_fail(nxt_task_t *task, nxt_http_source_t *hs);
static void nxt_http_source_message(const char *msg, size_t len, u_char *p);
void
-nxt_http_source_handler(nxt_upstream_source_t *us,
+nxt_http_source_handler(nxt_task_t *task, nxt_upstream_source_t *us,
nxt_http_source_request_create_t request_create)
{
nxt_http_source_t *hs;
@@ -99,13 +100,13 @@ nxt_http_source_handler(nxt_upstream_source_t *us,
if (nxt_fast_path(stream->out != NULL)) {
nxt_memzero(&hs->u.status_parse, sizeof(nxt_http_status_parse_t));
- nxt_stream_source_connect(stream);
+ nxt_stream_source_connect(task, stream);
return;
}
fail:
- nxt_http_source_fail(hs);
+ nxt_http_source_fail(task, hs);
}
@@ -184,7 +185,7 @@ new_buffer:
static void
-nxt_http_source_status_filter(nxt_thread_t *thr, void *obj, void *data)
+nxt_http_source_status_filter(nxt_task_t *task, void *obj, void *data)
{
nxt_int_t ret;
nxt_buf_t *b;
@@ -198,10 +199,10 @@ nxt_http_source_status_filter(nxt_thread_t *thr, void *obj, void *data)
* start the stream source passes buffers one at a time.
*/
- nxt_log_debug(thr->log, "http source status filter");
+ nxt_debug(task, "http source status filter");
if (nxt_slow_path(nxt_buf_is_sync(b))) {
- nxt_http_source_sync_buffer(thr, hs, b);
+ nxt_http_source_sync_buffer(task, hs, b);
return;
}
@@ -214,28 +215,28 @@ nxt_http_source_status_filter(nxt_thread_t *thr, void *obj, void *data)
*/
hs->query.filter = nxt_http_source_header_filter;
- nxt_log_debug(thr->log, "upstream status: \"%*s\"",
- hs->u.status_parse.end - b->mem.start, b->mem.start);
+ nxt_debug(task, "upstream status: \"%*s\"",
+ hs->u.status_parse.end - b->mem.start, b->mem.start);
hs->header_in.status = hs->u.status_parse.code;
- nxt_log_debug(thr->log, "upstream version:%d status:%uD \"%*s\"",
- hs->u.status_parse.http_version,
- hs->u.status_parse.code,
- hs->u.status_parse.end - hs->u.status_parse.start,
- hs->u.status_parse.start);
+ nxt_debug(task, "upstream version:%d status:%uD \"%*s\"",
+ hs->u.status_parse.http_version,
+ hs->u.status_parse.code,
+ hs->u.status_parse.end - hs->u.status_parse.start,
+ hs->u.status_parse.start);
nxt_memzero(&hs->u.header, sizeof(nxt_http_split_header_parse_t));
hs->u.header.mem_pool = hs->upstream->buffers.mem_pool;
- nxt_http_source_header_filter(thr, hs, b);
+ nxt_http_source_header_filter(task, hs, b);
return;
}
if (nxt_slow_path(ret == NXT_ERROR)) {
/* HTTP/0.9 response. */
hs->header_in.status = 200;
- nxt_http_source_header_ready(hs, b);
+ nxt_http_source_header_ready(task, hs, b);
return;
}
@@ -251,13 +252,13 @@ nxt_http_source_status_filter(nxt_thread_t *thr, void *obj, void *data)
nxt_http_source_message("upstream sent too long status line: \"%*s\"",
b->mem.pos - b->mem.start, b->mem.start);
- nxt_http_source_fail(hs);
+ nxt_http_source_fail(task, hs);
}
}
static void
-nxt_http_source_header_filter(nxt_thread_t *thr, void *obj, void *data)
+nxt_http_source_header_filter(nxt_task_t *task, void *obj, void *data)
{
nxt_int_t ret;
nxt_buf_t *b;
@@ -271,10 +272,10 @@ nxt_http_source_header_filter(nxt_thread_t *thr, void *obj, void *data)
* start the stream source passes buffers one at a time.
*/
- nxt_log_debug(thr->log, "http source header filter");
+ nxt_debug(task, "http source header filter");
if (nxt_slow_path(nxt_buf_is_sync(b))) {
- nxt_http_source_sync_buffer(thr, hs, b);
+ nxt_http_source_sync_buffer(task, hs, b);
return;
}
@@ -293,8 +294,8 @@ nxt_http_source_header_filter(nxt_thread_t *thr, void *obj, void *data)
}
if (nxt_fast_path(ret == NXT_DONE)) {
- nxt_log_debug(thr->log, "http source header done");
- nxt_http_source_header_ready(hs, b);
+ nxt_debug(task, "http source header done");
+ nxt_http_source_header_ready(task, hs, b);
return;
}
@@ -304,16 +305,16 @@ nxt_http_source_header_filter(nxt_thread_t *thr, void *obj, void *data)
if (ret != NXT_ERROR) {
/* ret == NXT_DECLINED: "\r" is not followed by "\n" */
- nxt_log_error(NXT_LOG_ERR, thr->log,
- "upstream sent invalid header line: \"%*s\\r...\"",
- hs->u.header.parse.header_end
- - hs->u.header.parse.header_name_start,
- hs->u.header.parse.header_name_start);
+ nxt_log(task, NXT_LOG_ERR,
+ "upstream sent invalid header line: \"%*s\\r...\"",
+ hs->u.header.parse.header_end
+ - hs->u.header.parse.header_name_start,
+ hs->u.header.parse.header_name_start);
}
/* ret == NXT_ERROR */
- nxt_http_source_fail(hs);
+ nxt_http_source_fail(task, hs);
}
@@ -425,7 +426,8 @@ nxt_http_source_transfer_encoding(nxt_upstream_source_t *us,
static void
-nxt_http_source_header_ready(nxt_http_source_t *hs, nxt_buf_t *rest)
+nxt_http_source_header_ready(nxt_task_t *task, nxt_http_source_t *hs,
+ nxt_buf_t *rest)
{
nxt_buf_t *b;
nxt_upstream_source_t *us;
@@ -461,7 +463,7 @@ nxt_http_source_header_ready(nxt_http_source_t *hs, nxt_buf_t *rest)
hsc->parse.mem_pool = hs->upstream->buffers.mem_pool;
if (nxt_buf_mem_used_size(&rest->mem) != 0) {
- hs->rest = nxt_http_chunk_parse(&hsc->parse, rest);
+ hs->rest = nxt_http_chunk_parse(task, &hsc->parse, rest);
if (nxt_slow_path(hs->rest == NULL)) {
goto fail;
@@ -489,12 +491,12 @@ nxt_http_source_header_ready(nxt_http_source_t *hs, nxt_buf_t *rest)
us->buffers.max, us->buffers.size / 1024);
fail:
- nxt_http_source_fail(hs);
+ nxt_http_source_fail(task, hs);
}
static void
-nxt_http_source_chunk_filter(nxt_thread_t *thr, void *obj, void *data)
+nxt_http_source_chunk_filter(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b;
nxt_http_source_t *hs;
@@ -503,37 +505,39 @@ nxt_http_source_chunk_filter(nxt_thread_t *thr, void *obj, void *data)
hsc = obj;
b = data;
- nxt_log_debug(thr->log, "http source chunk filter");
+ nxt_debug(task, "http source chunk filter");
- b = nxt_http_chunk_parse(&hsc->parse, b);
+ b = nxt_http_chunk_parse(task, &hsc->parse, b);
hs = hsc->next.context;
if (hsc->parse.error) {
- nxt_http_source_fail(hs);
+ nxt_http_source_fail(task, hs);
return;
}
if (hsc->parse.chunk_error) {
/* Output all parsed before a chunk error and close upstream. */
- nxt_thread_current_work_queue_add(thr, nxt_http_source_chunk_error,
- hs, NULL, thr->log);
+ nxt_thread_current_work_queue_add(task->thread,
+ nxt_http_source_chunk_error,
+ task, hs, NULL);
}
if (b != NULL) {
- nxt_source_filter(thr, hs->upstream->work_queue, &hsc->next, b);
+ nxt_source_filter(task->thread, hs->upstream->work_queue, task,
+ &hsc->next, b);
}
}
static void
-nxt_http_source_chunk_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_http_source_chunk_error(nxt_task_t *task, void *obj, void *data)
{
nxt_http_source_t *hs;
hs = obj;
- nxt_http_source_fail(hs);
+ nxt_http_source_fail(task, hs);
}
@@ -543,7 +547,7 @@ nxt_http_source_chunk_error(nxt_thread_t *thr, void *obj, void *data)
*/
static void
-nxt_http_source_body_filter(nxt_thread_t *thr, void *obj, void *data)
+nxt_http_source_body_filter(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b, *in;
nxt_http_source_t *hs;
@@ -551,7 +555,7 @@ nxt_http_source_body_filter(nxt_thread_t *thr, void *obj, void *data)
hs = obj;
in = data;
- nxt_log_debug(thr->log, "http source body filter");
+ nxt_debug(task, "http source body filter");
for (b = in; b != NULL; b = b->next) {
@@ -562,7 +566,8 @@ nxt_http_source_body_filter(nxt_thread_t *thr, void *obj, void *data)
}
if (hs->next != NULL) {
- nxt_source_filter(thr, hs->upstream->work_queue, hs->next, in);
+ nxt_source_filter(task->thread, hs->upstream->work_queue, task,
+ hs->next, in);
return;
}
@@ -571,50 +576,45 @@ nxt_http_source_body_filter(nxt_thread_t *thr, void *obj, void *data)
static void
-nxt_http_source_sync_buffer(nxt_thread_t *thr, nxt_http_source_t *hs,
+nxt_http_source_sync_buffer(nxt_task_t *task, nxt_http_source_t *hs,
nxt_buf_t *b)
{
if (nxt_buf_is_last(b)) {
- nxt_log_error(NXT_LOG_ERR, thr->log,
- "upstream closed prematurely connection");
+ nxt_log(task, NXT_LOG_ERR,
+ "upstream closed prematurely connection");
} else {
- nxt_log_error(NXT_LOG_ERR, thr->log, "%ui buffers %uz each are not "
- "enough to process upstream response header",
- hs->upstream->buffers.max,
- hs->upstream->buffers.size);
+ nxt_log(task, NXT_LOG_ERR,"%ui buffers %uz each are not "
+ "enough to process upstream response header",
+ hs->upstream->buffers.max, hs->upstream->buffers.size);
}
/* The stream source sends only the last and the nobuf sync buffer. */
- nxt_http_source_fail(hs);
+ nxt_http_source_fail(task, hs);
}
static void
-nxt_http_source_error(nxt_stream_source_t *stream)
+nxt_http_source_error(nxt_task_t *task, nxt_stream_source_t *stream)
{
nxt_http_source_t *hs;
nxt_thread_log_debug("http source error");
hs = stream->next->context;
- nxt_http_source_fail(hs);
+ nxt_http_source_fail(task, hs);
}
static void
-nxt_http_source_fail(nxt_http_source_t *hs)
+nxt_http_source_fail(nxt_task_t *task, nxt_http_source_t *hs)
{
- nxt_thread_t *thr;
-
- thr = nxt_thread();
-
- nxt_log_debug(thr->log, "http source fail");
+ nxt_debug(task, "http source fail");
/* TODO: fail, next upstream, or bad gateway */
- hs->upstream->state->error_handler(thr, hs, NULL);
+ hs->upstream->state->error_handler(task, hs, NULL);
}
diff --git a/src/nxt_http_source.h b/src/nxt_http_source.h
index 53924a4f..07d0db0d 100644
--- a/src/nxt_http_source.h
+++ b/src/nxt_http_source.h
@@ -40,8 +40,8 @@ struct nxt_http_source_s {
};
-NXT_EXPORT void nxt_http_source_handler(nxt_upstream_source_t *us,
- nxt_http_source_request_create_t request_create);
+NXT_EXPORT void nxt_http_source_handler(nxt_task_t *task,
+ nxt_upstream_source_t *us, nxt_http_source_request_create_t request_create);
NXT_EXPORT nxt_int_t nxt_http_source_hash_create(nxt_mem_pool_t *mp,
nxt_lvlhsh_t *lh);
diff --git a/src/nxt_job.c b/src/nxt_job.c
index 2b7d8818..e1256d61 100644
--- a/src/nxt_job.c
+++ b/src/nxt_job.c
@@ -8,8 +8,8 @@
#if (NXT_THREADS)
-static void nxt_job_thread_trampoline(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_job_thread_return_handler(nxt_thread_t *thr, void *obj,
+static void nxt_job_thread_trampoline(nxt_task_t *task, void *obj, void *data);
+static void nxt_job_thread_return_handler(nxt_task_t *task, void *obj,
void *data);
#endif
@@ -44,6 +44,8 @@ nxt_job_create(nxt_mem_pool_t *mp, size_t size)
/* Allow safe nxt_queue_remove() in nxt_job_destroy(). */
nxt_queue_self(&job->link);
+ job->task.ident = nxt_task_next_ident();
+
return job;
}
@@ -56,6 +58,8 @@ nxt_job_init(nxt_job_t *job, size_t size)
nxt_job_set_name(job, "job");
nxt_queue_self(&job->link);
+
+ job->task.ident = nxt_task_next_ident();
}
@@ -103,18 +107,19 @@ nxt_job_cleanup_add(nxt_mem_pool_t *mp, nxt_job_t *job)
*/
void
-nxt_job_start(nxt_thread_t *thr, nxt_job_t *job, nxt_work_handler_t handler)
+nxt_job_start(nxt_task_t *task, nxt_job_t *job, nxt_work_handler_t handler)
{
- nxt_log_debug(thr->log, "%s start", job->name);
+ nxt_debug(task, "%s start", job->name);
#if (NXT_THREADS)
if (job->thread_pool != NULL) {
nxt_int_t ret;
- job->engine = thr->engine;
+ job->engine = task->thread->engine;
+
ret = nxt_thread_pool_post(job->thread_pool, nxt_job_thread_trampoline,
- job, (void *) handler, job->log);
+ &job->task, job, (void *) handler);
if (ret == NXT_OK) {
return;
}
@@ -124,7 +129,7 @@ nxt_job_start(nxt_thread_t *thr, nxt_job_t *job, nxt_work_handler_t handler)
#endif
- handler(thr, job, job->data);
+ handler(&job->task, job, job->data);
}
@@ -133,7 +138,7 @@ nxt_job_start(nxt_thread_t *thr, nxt_job_t *job, nxt_work_handler_t handler)
/* A trampoline function is called by a thread pool thread. */
static void
-nxt_job_thread_trampoline(nxt_thread_t *thr, void *obj, void *data)
+nxt_job_thread_trampoline(nxt_task_t *task, void *obj, void *data)
{
nxt_job_t *job;
nxt_work_handler_t handler;
@@ -141,13 +146,15 @@ nxt_job_thread_trampoline(nxt_thread_t *thr, void *obj, void *data)
job = obj;
handler = (nxt_work_handler_t) data;
- nxt_log_debug(thr->log, "%s thread", job->name);
+ job->task.log = job->log;
+
+ nxt_debug(task, "%s thread", job->name);
if (nxt_slow_path(job->cancel)) {
- nxt_job_return(thr, job, job->abort_handler);
+ nxt_job_return(task, job, job->abort_handler);
} else {
- handler(thr, job, job->data);
+ handler(&job->task, job, job->data);
}
}
@@ -155,35 +162,35 @@ nxt_job_thread_trampoline(nxt_thread_t *thr, void *obj, void *data)
void
-nxt_job_return(nxt_thread_t *thr, nxt_job_t *job, nxt_work_handler_t handler)
+nxt_job_return(nxt_task_t *task, nxt_job_t *job, nxt_work_handler_t handler)
{
- nxt_log_debug(thr->log, "%s return", job->name);
+ nxt_debug(task, "%s return", job->name);
#if (NXT_THREADS)
if (job->engine != NULL) {
/* A return function is called in thread pool thread context. */
nxt_event_engine_post(job->engine, nxt_job_thread_return_handler,
- job, (void *) handler, job->log);
+ &job->task, job, (void *) handler, job->log);
return;
}
#endif
if (nxt_slow_path(job->cancel)) {
- nxt_log_debug(thr->log, "%s cancellation", job->name);
+ nxt_debug(task, "%s cancellation", job->name);
handler = job->abort_handler;
}
- nxt_thread_work_queue_push(thr, &thr->work_queue.main,
- handler, job, job->data, thr->log);
+ nxt_thread_work_queue_push(task->thread, &task->thread->work_queue.main,
+ handler, &job->task, job, job->data);
}
#if (NXT_THREADS)
static void
-nxt_job_thread_return_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_job_thread_return_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_job_t *job;
nxt_work_handler_t handler;
@@ -191,12 +198,14 @@ nxt_job_thread_return_handler(nxt_thread_t *thr, void *obj, void *data)
job = obj;
handler = (nxt_work_handler_t) data;
+ job->task.thread = task->thread;
+
if (nxt_slow_path(job->cancel)) {
- nxt_log_debug(thr->log, "%s cancellation", job->name);
+ nxt_debug(task, "%s cancellation", job->name);
handler = job->abort_handler;
}
- handler(thr, job, job->data);
+ handler(&job->task, job, job->data);
}
#endif
diff --git a/src/nxt_job.h b/src/nxt_job.h
index 320716ca..f1954b57 100644
--- a/src/nxt_job.h
+++ b/src/nxt_job.h
@@ -33,6 +33,8 @@
typedef struct {
void *data;
+ nxt_task_t task;
+
nxt_work_handler_t abort_handler;
uint16_t cache_size;
@@ -59,9 +61,9 @@ NXT_EXPORT void nxt_job_init(nxt_job_t *job, size_t size);
NXT_EXPORT void nxt_job_destroy(void *data);
NXT_EXPORT nxt_int_t nxt_job_cleanup_add(nxt_mem_pool_t *mp, nxt_job_t *job);
-NXT_EXPORT void nxt_job_start(nxt_thread_t *thr, nxt_job_t *job,
+NXT_EXPORT void nxt_job_start(nxt_task_t *task, nxt_job_t *job,
nxt_work_handler_t handler);
-NXT_EXPORT void nxt_job_return(nxt_thread_t *thr, nxt_job_t *job,
+NXT_EXPORT void nxt_job_return(nxt_task_t *task, nxt_job_t *job,
nxt_work_handler_t handler);
diff --git a/src/nxt_job_file.c b/src/nxt_job_file.c
index bbebdee6..34f7ce08 100644
--- a/src/nxt_job_file.c
+++ b/src/nxt_job_file.c
@@ -8,8 +8,7 @@
#include <nxt_main.h>
-static void nxt_job_file_open_and_read(nxt_thread_t *thr, void *obj,
- void *data);
+static void nxt_job_file_open_and_read(nxt_task_t *task, void *obj, void *data);
static nxt_int_t nxt_job_file_open(nxt_job_file_t *jbf);
static nxt_int_t nxt_job_file_info(nxt_job_file_t *jbf);
static nxt_int_t nxt_job_file_mmap(nxt_job_file_t *jbf, size_t size);
@@ -51,14 +50,14 @@ nxt_job_file_init(nxt_job_file_t *jbf)
*/
void
-nxt_job_file_read(nxt_thread_t *thr, nxt_job_t *job)
+nxt_job_file_read(nxt_task_t *task, nxt_job_t *job)
{
- nxt_job_start(thr, job, nxt_job_file_open_and_read);
+ nxt_job_start(task, job, nxt_job_file_open_and_read);
}
static void
-nxt_job_file_open_and_read(nxt_thread_t *thr, void *obj, void *data)
+nxt_job_file_open_and_read(nxt_task_t *task, void *obj, void *data)
{
size_t size;
nxt_int_t n;
@@ -70,7 +69,7 @@ nxt_job_file_open_and_read(nxt_thread_t *thr, void *obj, void *data)
jbf = obj;
file = &jbf->file;
- nxt_log_debug(thr->log, "file job read: \"%FN\"", file->name);
+ nxt_debug(task, "file job read: \"%FN\"", file->name);
if (file->fd != NXT_FILE_INVALID && jbf->close_before_open) {
nxt_file_close(file);
@@ -135,7 +134,7 @@ nxt_job_file_open_and_read(nxt_thread_t *thr, void *obj, void *data)
}
}
- nxt_job_return(thr, &jbf->job, jbf->ready_handler);
+ nxt_job_return(task, &jbf->job, jbf->ready_handler);
return;
done:
@@ -145,7 +144,7 @@ done:
file->fd = NXT_FILE_INVALID;
}
- nxt_job_return(thr, &jbf->job, handler);
+ nxt_job_return(task, &jbf->job, handler);
}
diff --git a/src/nxt_job_file.h b/src/nxt_job_file.h
index f61d517d..a1ccef06 100644
--- a/src/nxt_job_file.h
+++ b/src/nxt_job_file.h
@@ -68,7 +68,7 @@ struct nxt_job_file_s {
NXT_EXPORT nxt_job_file_t *nxt_job_file_create(nxt_mem_pool_t *mp);
NXT_EXPORT void nxt_job_file_init(nxt_job_file_t *jbf);
-NXT_EXPORT void nxt_job_file_read(nxt_thread_t *thr, nxt_job_t *job);
+NXT_EXPORT void nxt_job_file_read(nxt_task_t *task, nxt_job_t *job);
#endif /* _NXT_JOB_FILE_H_INCLUDED_ */
diff --git a/src/nxt_job_resolve.c b/src/nxt_job_resolve.c
index 600f1aae..e44acd14 100644
--- a/src/nxt_job_resolve.c
+++ b/src/nxt_job_resolve.c
@@ -121,5 +121,5 @@ fail:
freeaddrinfo(res);
}
- nxt_job_return(nxt_thread(), &jbr->job, handler);
+ nxt_job_return(&jbr->job.task, &jbr->job, handler);
}
diff --git a/src/nxt_kqueue.c b/src/nxt_kqueue.c
index 25d9eefe..7370a401 100644
--- a/src/nxt_kqueue.c
+++ b/src/nxt_kqueue.c
@@ -87,9 +87,9 @@ static void nxt_kqueue_fd_set(nxt_event_set_t *event_set, nxt_event_fd_t *ev,
static struct kevent *nxt_kqueue_get_kevent(nxt_kqueue_event_set_t *ks);
static void nxt_kqueue_commit_changes(nxt_kqueue_event_set_t *ks);
static void nxt_kqueue_error(nxt_kqueue_event_set_t *ks);
-static void nxt_kqueue_fd_error_handler(nxt_thread_t *thr, void *obj,
+static void nxt_kqueue_fd_error_handler(nxt_task_t *task, void *obj,
void *data);
-static void nxt_kqueue_file_error_handler(nxt_thread_t *thr, void *obj,
+static void nxt_kqueue_file_error_handler(nxt_task_t *task, void *obj,
void *data);
static nxt_int_t nxt_kqueue_add_signal(nxt_kqueue_event_set_t *kq,
const nxt_event_sig_t *sigev);
@@ -98,17 +98,17 @@ static nxt_int_t nxt_kqueue_enable_post(nxt_event_set_t *event_set,
nxt_work_handler_t handler);
static void nxt_kqueue_signal(nxt_event_set_t *event_set, nxt_uint_t signo);
#endif
-static void nxt_kqueue_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
+static void nxt_kqueue_poll(nxt_task_t *task, nxt_event_set_t *event_set,
nxt_msec_t timeout);
-static void nxt_kqueue_event_conn_io_connect(nxt_thread_t *thr, void *obj,
+static void nxt_kqueue_event_conn_io_connect(nxt_task_t *task, void *obj,
void *data);
-static void nxt_kqueue_event_conn_connected(nxt_thread_t *thr, void *obj,
+static void nxt_kqueue_event_conn_connected(nxt_task_t *task, void *obj,
void *data);
-static void nxt_kqueue_listen_handler(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_kqueue_event_conn_io_accept(nxt_thread_t *thr, void *obj,
+static void nxt_kqueue_listen_handler(nxt_task_t *task, void *obj, void *data);
+static void nxt_kqueue_event_conn_io_accept(nxt_task_t *task, void *obj,
void *data);
-static void nxt_kqueue_event_conn_io_read(nxt_thread_t *thr, void *obj,
+static void nxt_kqueue_event_conn_io_read(nxt_task_t *task, void *obj,
void *data);
static ssize_t nxt_kqueue_event_conn_io_recvbuf(nxt_event_conn_t *c,
nxt_buf_t *b);
@@ -547,14 +547,14 @@ nxt_kqueue_error(nxt_kqueue_event_set_t *ks)
ev = nxt_kevent_get_udata(kev->udata);
nxt_thread_work_queue_add(thr, &thr->work_queue.main,
nxt_kqueue_fd_error_handler,
- ev, ev->data, ev->log);
+ ev->task, ev, ev->data);
break;
case EVFILT_VNODE:
fev = nxt_kevent_get_udata(kev->udata);
nxt_thread_work_queue_add(thr, &thr->work_queue.main,
nxt_kqueue_file_error_handler,
- fev, fev->data, thr->log);
+ fev->task, fev, fev->data);
break;
}
}
@@ -562,7 +562,7 @@ nxt_kqueue_error(nxt_kqueue_event_set_t *ks)
static void
-nxt_kqueue_fd_error_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_kqueue_fd_error_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_event_fd_t *ev;
@@ -570,27 +570,27 @@ nxt_kqueue_fd_error_handler(nxt_thread_t *thr, void *obj, void *data)
if (ev->kq_eof && ev->kq_errno != 0) {
ev->error = ev->kq_errno;
- nxt_log_error(nxt_socket_error_level(ev->kq_errno, ev->log_error),
- thr->log, "kevent() reported error on descriptor %d %E",
- ev->fd, ev->kq_errno);
+ nxt_log(task, nxt_socket_error_level(ev->kq_errno, ev->log_error),
+ "kevent() reported error on descriptor %d %E",
+ ev->fd, ev->kq_errno);
}
ev->read = NXT_EVENT_INACTIVE;
ev->write = NXT_EVENT_INACTIVE;
ev->error = ev->kq_errno;
- ev->error_handler(thr, ev, data);
+ ev->error_handler(task, ev, data);
}
static void
-nxt_kqueue_file_error_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_kqueue_file_error_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_event_file_t *ev;
ev = obj;
- ev->handler(thr, ev, data);
+ ev->handler(task, ev, data);
}
@@ -696,16 +696,16 @@ nxt_kqueue_signal(nxt_event_set_t *event_set, nxt_uint_t signo)
static void
-nxt_kqueue_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
+nxt_kqueue_poll(nxt_task_t *task, nxt_event_set_t *event_set,
nxt_msec_t timeout)
{
int nevents;
void *obj, *data;
nxt_int_t i;
nxt_err_t err;
- nxt_log_t *log;
nxt_uint_t level;
nxt_bool_t error, eof;
+ nxt_task_t *event_task;
struct kevent *kev;
nxt_event_fd_t *ev;
nxt_event_sig_t *sigev;
@@ -726,21 +726,21 @@ nxt_kqueue_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
ks = &event_set->kqueue;
- nxt_log_debug(thr->log, "kevent(%d) changes:%d timeout:%M",
- ks->kqueue, ks->nchanges, timeout);
+ nxt_debug(task, "kevent(%d) changes:%d timeout:%M",
+ ks->kqueue, ks->nchanges, timeout);
nevents = kevent(ks->kqueue, ks->changes, ks->nchanges,
ks->events, ks->mevents, tp);
err = (nevents == -1) ? nxt_errno : 0;
- nxt_thread_time_update(thr);
+ nxt_thread_time_update(task->thread);
- nxt_log_debug(thr->log, "kevent(%d): %d", ks->kqueue, nevents);
+ nxt_debug(task, "kevent(%d): %d", ks->kqueue, nevents);
if (nevents == -1) {
level = (err == NXT_EINTR) ? NXT_LOG_INFO : NXT_LOG_ALERT;
- nxt_log_error(level, thr->log, "kevent(%d) failed %E", ks->kqueue, err);
+ nxt_log(task, level, "kevent(%d) failed %E", ks->kqueue, err);
nxt_kqueue_error(ks);
return;
@@ -752,24 +752,25 @@ nxt_kqueue_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
kev = &ks->events[i];
- nxt_log_debug(thr->log,
- (kev->ident > 0x8000000 && kev->ident != (uintptr_t) -1) ?
- "kevent: id:%p ft:%d fl:%04Xd ff:%d d:%d ud:%p":
- "kevent: id:%d ft:%d fl:%04Xd ff:%d d:%d ud:%p",
- kev->ident, kev->filter, kev->flags, kev->fflags,
- kev->data, kev->udata);
+ nxt_debug(task,
+ (kev->ident > 0x8000000 && kev->ident != (uintptr_t) -1) ?
+ "kevent: id:%p ft:%d fl:%04Xd ff:%d d:%d ud:%p":
+ "kevent: id:%d ft:%d fl:%04Xd ff:%d d:%d ud:%p",
+ kev->ident, kev->filter, kev->flags, kev->fflags,
+ kev->data, kev->udata);
error = (kev->flags & EV_ERROR);
if (nxt_slow_path(error)) {
- nxt_log_alert(thr->log, "kevent(%d) error %E on ident:%d filter:%d",
- ks->kqueue, kev->data, kev->ident, kev->filter);
+ nxt_log(task, NXT_LOG_CRIT,
+ "kevent(%d) error %E on ident:%d filter:%d",
+ ks->kqueue, kev->data, kev->ident, kev->filter);
}
- wq = &thr->work_queue.main;
+ event_task = task;
+ wq = &task->thread->work_queue.main;
handler = nxt_kqueue_fd_error_handler;
obj = nxt_kevent_get_udata(kev->udata);
- log = thr->log;
switch (kev->filter) {
@@ -783,7 +784,7 @@ nxt_kqueue_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
ev->kq_eof = eof;
if (ev->read == NXT_EVENT_BLOCKED) {
- nxt_log_debug(ev->log, "blocked read event fd:%d", ev->fd);
+ nxt_debug(ev->task, "blocked read event fd:%d", ev->fd);
continue;
}
@@ -800,8 +801,8 @@ nxt_kqueue_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
wq = ev->read_work_queue;
}
+ event_task = ev->task;
data = ev->data;
- log = ev->log;
break;
@@ -814,7 +815,7 @@ nxt_kqueue_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
ev->kq_eof = eof;
if (ev->write == NXT_EVENT_BLOCKED) {
- nxt_log_debug(ev->log, "blocked write event fd:%d", ev->fd);
+ nxt_debug(ev->task, "blocked write event fd:%d", ev->fd);
continue;
}
@@ -831,14 +832,15 @@ nxt_kqueue_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
wq = ev->write_work_queue;
}
+ event_task = ev->task;
data = ev->data;
- log = ev->log;
break;
case EVFILT_VNODE:
fev = obj;
handler = fev->handler;
+ event_task = fev->task;
data = fev->data;
break;
@@ -861,15 +863,16 @@ nxt_kqueue_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
default:
#if (NXT_DEBUG)
- nxt_log_alert(thr->log,
- "unexpected kevent(%d) filter %d on ident %d",
- ks->kqueue, kev->filter, kev->ident);
+ nxt_log(task, NXT_LOG_CRIT,
+ "unexpected kevent(%d) filter %d on ident %d",
+ ks->kqueue, kev->filter, kev->ident);
#endif
continue;
}
- nxt_thread_work_queue_add(thr, wq, handler, obj, data, log);
+ nxt_thread_work_queue_add(task->thread, wq, handler,
+ event_task, obj, data);
}
}
@@ -880,7 +883,7 @@ nxt_kqueue_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
*/
static void
-nxt_kqueue_event_conn_io_connect(nxt_thread_t *thr, void *obj, void *data)
+nxt_kqueue_event_conn_io_connect(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_work_handler_t handler;
@@ -901,9 +904,9 @@ nxt_kqueue_event_conn_io_connect(nxt_thread_t *thr, void *obj, void *data)
c->socket.write_handler = nxt_kqueue_event_conn_connected;
c->socket.error_handler = nxt_event_conn_connect_error;
- nxt_event_conn_timer(thr->engine, c, state, &c->write_timer);
+ nxt_event_conn_timer(task->thread->engine, c, state, &c->write_timer);
- nxt_kqueue_enable_write(thr->engine->event_set, &c->socket);
+ nxt_kqueue_enable_write(task->thread->engine->event_set, &c->socket);
return;
case NXT_DECLINED:
@@ -915,18 +918,19 @@ nxt_kqueue_event_conn_io_connect(nxt_thread_t *thr, void *obj, void *data)
break;
}
- nxt_event_conn_io_handle(thr, c->write_work_queue, handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue, handler, task,
+ c, data);
}
static void
-nxt_kqueue_event_conn_connected(nxt_thread_t *thr, void *obj, void *data)
+nxt_kqueue_event_conn_connected(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
c = obj;
- nxt_log_debug(thr->log, "kqueue event conn connected fd:%d", c->socket.fd);
+ nxt_debug(task, "kqueue event conn connected fd:%d", c->socket.fd);
c->socket.write = NXT_EVENT_BLOCKED;
@@ -934,30 +938,29 @@ nxt_kqueue_event_conn_connected(nxt_thread_t *thr, void *obj, void *data)
nxt_event_timer_disable(&c->write_timer);
}
- nxt_thread_work_queue_add(thr, c->write_work_queue,
- c->write_state->ready_handler,
- c, data, c->socket.log);
+ nxt_thread_work_queue_add(task->thread, c->write_work_queue,
+ c->write_state->ready_handler, task, c, data);
}
static void
-nxt_kqueue_listen_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_kqueue_listen_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_listen_t *cls;
cls = obj;
- nxt_log_debug(thr->log, "kevent fd:%d avail:%D",
- cls->socket.fd, cls->socket.kq_available);
+ nxt_debug(task, "kevent fd:%d avail:%D",
+ cls->socket.fd, cls->socket.kq_available);
cls->ready = nxt_min(cls->batch, (uint32_t) cls->socket.kq_available);
- nxt_kqueue_event_conn_io_accept(thr, cls, data);
+ nxt_kqueue_event_conn_io_accept(task, cls, data);
}
static void
-nxt_kqueue_event_conn_io_accept(nxt_thread_t *thr, void *obj, void *data)
+nxt_kqueue_event_conn_io_accept(nxt_task_t *task, void *obj, void *data)
{
socklen_t len;
nxt_socket_t s;
@@ -989,13 +992,13 @@ nxt_kqueue_event_conn_io_accept(nxt_thread_t *thr, void *obj, void *data)
if (s != -1) {
c->socket.fd = s;
- nxt_log_debug(thr->log, "accept(%d): %d", cls->socket.fd, s);
+ nxt_debug(task, "accept(%d): %d", cls->socket.fd, s);
- nxt_event_conn_accept(thr, cls, c);
+ nxt_event_conn_accept(task, cls, c);
return;
}
- nxt_event_conn_accept_error(thr, cls, "accept", nxt_errno);
+ nxt_event_conn_accept_error(task, cls, "accept", nxt_errno);
}
@@ -1005,25 +1008,24 @@ nxt_kqueue_event_conn_io_accept(nxt_thread_t *thr, void *obj, void *data)
*/
static void
-nxt_kqueue_event_conn_io_read(nxt_thread_t *thr, void *obj, void *data)
+nxt_kqueue_event_conn_io_read(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
c = obj;
- nxt_log_debug(thr->log, "kqueue event conn read fd:%d", c->socket.fd);
+ nxt_debug(task, "kqueue event conn read fd:%d", c->socket.fd);
if (c->socket.kq_available == 0 && c->socket.kq_eof) {
- nxt_log_debug(thr->log, "kevent fd:%d eof", c->socket.fd);
+ nxt_debug(task, "kevent fd:%d eof", c->socket.fd);
c->socket.closed = 1;
- nxt_thread_work_queue_add(thr, c->read_work_queue,
- c->read_state->close_handler,
- c, data, c->socket.log);
+ nxt_thread_work_queue_add(task->thread, c->read_work_queue,
+ c->read_state->close_handler, task, c, data);
return;
}
- nxt_event_conn_io_read(thr, c, data);
+ nxt_event_conn_io_read(task, c, data);
}
diff --git a/src/nxt_lib.c b/src/nxt_lib.c
index 2013a4f6..ee36c91a 100644
--- a/src/nxt_lib.c
+++ b/src/nxt_lib.c
@@ -9,6 +9,8 @@
nxt_uint_t nxt_ncpu = 1;
nxt_uint_t nxt_pagesize;
+nxt_task_t nxt_main_task;
+nxt_atomic_t nxt_task_ident;
nxt_random_t nxt_random_data;
nxt_thread_declare_data(nxt_thread_t, nxt_thread_context);
@@ -70,6 +72,10 @@ nxt_lib_start(const char *app, char **argv, char ***envp)
thr->time.signal = -1;
#endif
+ nxt_main_task.thread = thr;
+ nxt_main_task.log = thr->log;
+ nxt_main_task.ident = nxt_task_next_ident();
+
if (nxt_strerror_start() != NXT_OK) {
return NXT_ERROR;
}
diff --git a/src/nxt_linux_sendfile.c b/src/nxt_linux_sendfile.c
index 9c8f563c..1dbac677 100644
--- a/src/nxt_linux_sendfile.c
+++ b/src/nxt_linux_sendfile.c
@@ -62,7 +62,7 @@ nxt_linux_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b,
sb.size = 0;
sb.limit = limit;
- niov = nxt_sendbuf_mem_coalesce(&sb);
+ niov = nxt_sendbuf_mem_coalesce(c->socket.task, &sb);
if (niov == 0 && sb.sync) {
return 0;
diff --git a/src/nxt_log.c b/src/nxt_log.c
index 95591f18..cd2b5d70 100644
--- a/src/nxt_log.c
+++ b/src/nxt_log.c
@@ -8,6 +8,8 @@
nxt_uint_t nxt_debug;
+nxt_uint_t nxt_trace;
+
nxt_log_t nxt_main_log = {
NXT_LOG_INFO,
diff --git a/src/nxt_log.h b/src/nxt_log.h
index cbd7d09b..d04bc3dd 100644
--- a/src/nxt_log.h
+++ b/src/nxt_log.h
@@ -66,6 +66,27 @@ nxt_log_alert(_log, ...) \
} while (0)
+#define nxt_log(task, _level, ...) \
+ do { \
+ nxt_log_t *log = (task)->log; \
+ nxt_uint_t _level_ = (_level); \
+ \
+ if (nxt_slow_path(log->level >= _level_)) { \
+ log->handler(_level_, log, __VA_ARGS__); \
+ } \
+ } while (0)
+
+
+#define nxt_trace(task, ...) \
+ do { \
+ nxt_log_t *log = (task)->log; \
+ \
+ if (nxt_slow_path(log->level >= NXT_LOG_NOTICE || nxt_trace)) { \
+ log->handler(NXT_LOG_NOTICE, log, __VA_ARGS__); \
+ } \
+ } while (0)
+
+
#define \
nxt_log_error(_level, _log, ...) \
do { \
@@ -80,6 +101,16 @@ nxt_log_error(_level, _log, ...) \
#if (NXT_DEBUG)
+#define nxt_debug(task, ...) \
+ do { \
+ nxt_log_t *log = (task)->log; \
+ \
+ if (nxt_slow_path(log->level == NXT_LOG_DEBUG || nxt_debug)) { \
+ log->handler(NXT_LOG_DEBUG, log, __VA_ARGS__); \
+ } \
+ } while (0)
+
+
#define \
nxt_log_debug(_log, ...) \
do { \
@@ -92,6 +123,8 @@ nxt_log_debug(_log, ...) \
#else
+#define nxt_log_debug(...)
+
#define \
nxt_log_debug(...)
@@ -119,6 +152,7 @@ nxt_main_log_debug(...) \
NXT_EXPORT extern nxt_uint_t nxt_debug;
+NXT_EXPORT extern nxt_uint_t nxt_trace;
NXT_EXPORT extern nxt_log_t nxt_main_log;
NXT_EXPORT extern nxt_str_t nxt_log_levels[];
diff --git a/src/nxt_log_moderation.c b/src/nxt_log_moderation.c
index bba379de..5082270d 100644
--- a/src/nxt_log_moderation.c
+++ b/src/nxt_log_moderation.c
@@ -7,7 +7,7 @@
#include <nxt_main.h>
-static void nxt_log_moderate_timer_handler(nxt_thread_t *thr, void *obj,
+static void nxt_log_moderate_timer_handler(nxt_task_t *task, void *obj,
void *data);
@@ -70,7 +70,7 @@ nxt_log_moderate_allow(nxt_log_moderation_t *mod)
static void
-nxt_log_moderate_timer_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_log_moderate_timer_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_bool_t msg;
nxt_atomic_uint_t n;
@@ -82,7 +82,7 @@ nxt_log_moderate_timer_handler(nxt_thread_t *thr, void *obj, void *data)
nxt_thread_spin_lock(&mod->lock);
- mod->last = nxt_thread_time(thr);
+ mod->last = nxt_thread_time(task->thread);
n = mod->count;
mod->count = 0;
msg = (mod->pid == nxt_pid);
diff --git a/src/nxt_macosx_sendfile.c b/src/nxt_macosx_sendfile.c
index 94a76718..34a586c3 100644
--- a/src/nxt_macosx_sendfile.c
+++ b/src/nxt_macosx_sendfile.c
@@ -46,7 +46,7 @@ nxt_macosx_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b,
sb.size = 0;
sb.limit = limit;
- nhd = nxt_sendbuf_mem_coalesce(&sb);
+ nhd = nxt_sendbuf_mem_coalesce(c->socket.task, &sb);
if (nhd == 0 && sb.sync) {
return 0;
@@ -67,7 +67,7 @@ nxt_macosx_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b,
sb.iobuf = tr;
- ntr = nxt_sendbuf_mem_coalesce(&sb);
+ ntr = nxt_sendbuf_mem_coalesce(c->socket.task, &sb);
/*
* Disposal of surplus kernel operations if there are no headers
diff --git a/src/nxt_main.c b/src/nxt_main.c
index ea2061d6..76cbc0bb 100644
--- a/src/nxt_main.c
+++ b/src/nxt_main.c
@@ -32,7 +32,7 @@ main(int argc, char **argv)
nxt_log_error(NXT_LOG_INFO, thr->log, "nginman started");
- ret = nxt_cycle_create(thr, NULL, NULL, &nxt_config_name, 0);
+ ret = nxt_cycle_create(thr, &nxt_main_task, NULL, NULL, &nxt_config_name);
if (ret != NXT_OK) {
return 1;
diff --git a/src/nxt_main.h b/src/nxt_main.h
index 24fb80cd..3c52d69f 100644
--- a/src/nxt_main.h
+++ b/src/nxt_main.h
@@ -174,6 +174,8 @@ NXT_EXPORT void nxt_lib_stop(void);
NXT_EXPORT extern nxt_uint_t nxt_ncpu;
NXT_EXPORT extern nxt_uint_t nxt_pagesize;
+NXT_EXPORT extern nxt_task_t nxt_main_task;
+NXT_EXPORT extern nxt_atomic_t nxt_task_ident;
NXT_EXPORT extern nxt_random_t nxt_random_data;
diff --git a/src/nxt_master_process.c b/src/nxt_master_process.c
index df2934c0..8ce6e670 100644
--- a/src/nxt_master_process.c
+++ b/src/nxt_master_process.c
@@ -10,28 +10,31 @@
#include <nxt_master_process.h>
-static nxt_int_t nxt_master_process_chan_create(nxt_cycle_t *cycle);
+static nxt_int_t nxt_master_process_chan_create(nxt_task_t *task,
+ nxt_cycle_t *cycle);
static void nxt_master_process_title(void);
-static nxt_int_t nxt_master_start_worker_processes(nxt_cycle_t *cycle);
-static nxt_int_t nxt_master_create_worker_process(nxt_cycle_t *cycle);
-static void nxt_master_stop_previous_worker_processes(nxt_thread_t *thr,
+static nxt_int_t nxt_master_start_worker_processes(nxt_task_t *task,
+ nxt_cycle_t *cycle);
+static nxt_int_t nxt_master_create_worker_process(nxt_task_t *task,
+ nxt_cycle_t *cycle);
+static void nxt_master_stop_previous_worker_processes(nxt_task_t *task,
void *obj, void *data);
-static void nxt_master_process_sighup_handler(nxt_thread_t *thr, void *obj,
+static void nxt_master_process_sighup_handler(nxt_task_t *task, void *obj,
void *data);
-static void nxt_master_process_new_cycle(nxt_thread_t *thr, nxt_cycle_t *cycle);
-static void nxt_master_process_sigterm_handler(nxt_thread_t *thr, void *obj,
+static void nxt_master_process_new_cycle(nxt_task_t *task, nxt_cycle_t *cycle);
+static void nxt_master_process_sigterm_handler(nxt_task_t *task, void *obj,
void *data);
-static void nxt_master_process_sigquit_handler(nxt_thread_t *thr, void *obj,
+static void nxt_master_process_sigquit_handler(nxt_task_t *task, void *obj,
void *data);
-static void nxt_master_process_sigusr1_handler(nxt_thread_t *thr, void *obj,
+static void nxt_master_process_sigusr1_handler(nxt_task_t *task, void *obj,
void *data);
-static void nxt_master_process_sigusr2_handler(nxt_thread_t *thr, void *obj,
+static void nxt_master_process_sigusr2_handler(nxt_task_t *task, void *obj,
void *data);
static char **nxt_master_process_upgrade_environment(nxt_cycle_t *cycle);
static char **nxt_master_process_upgrade_environment_create(nxt_cycle_t *cycle);
-static void nxt_master_process_sigchld_handler(nxt_thread_t *thr, void *obj,
+static void nxt_master_process_sigchld_handler(nxt_task_t *task, void *obj,
void *data);
-static void nxt_master_cleanup_worker_process(nxt_thread_t *thr, nxt_pid_t pid);
+static void nxt_master_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid);
const nxt_event_sig_t nxt_master_process_signals[] = {
@@ -50,22 +53,23 @@ static nxt_bool_t nxt_exiting;
nxt_int_t
-nxt_master_process_start(nxt_thread_t *thr, nxt_cycle_t *cycle)
+nxt_master_process_start(nxt_thread_t *thr, nxt_task_t *task,
+ nxt_cycle_t *cycle)
{
cycle->type = NXT_PROCESS_MASTER;
- if (nxt_master_process_chan_create(cycle) != NXT_OK) {
+ if (nxt_master_process_chan_create(task, cycle) != NXT_OK) {
return NXT_ERROR;
}
nxt_master_process_title();
- return nxt_master_start_worker_processes(cycle);
+ return nxt_master_start_worker_processes(task, cycle);
}
static nxt_int_t
-nxt_master_process_chan_create(nxt_cycle_t *cycle)
+nxt_master_process_chan_create(nxt_task_t *task, nxt_cycle_t *cycle)
{
nxt_process_chan_t *proc;
@@ -86,7 +90,7 @@ nxt_master_process_chan_create(nxt_cycle_t *cycle)
* A master process chan. A write chan is not closed
* since it should be inherited by worker processes.
*/
- nxt_chan_read_enable(nxt_thread(), proc->chan);
+ nxt_chan_read_enable(task, proc->chan);
return NXT_OK;
}
@@ -115,7 +119,7 @@ nxt_master_process_title(void)
static nxt_int_t
-nxt_master_start_worker_processes(nxt_cycle_t *cycle)
+nxt_master_start_worker_processes(nxt_task_t *task, nxt_cycle_t *cycle)
{
nxt_int_t ret;
nxt_uint_t n;
@@ -125,7 +129,7 @@ nxt_master_start_worker_processes(nxt_cycle_t *cycle)
n = cycle->worker_processes;
while (n-- != 0) {
- ret = nxt_master_create_worker_process(cycle);
+ ret = nxt_master_create_worker_process(task, cycle);
if (ret != NXT_OK) {
return ret;
@@ -137,7 +141,7 @@ nxt_master_start_worker_processes(nxt_cycle_t *cycle)
static nxt_int_t
-nxt_master_create_worker_process(nxt_cycle_t *cycle)
+nxt_master_create_worker_process(nxt_task_t *task, nxt_cycle_t *cycle)
{
nxt_pid_t pid;
nxt_process_chan_t *proc;
@@ -174,41 +178,46 @@ nxt_master_create_worker_process(nxt_cycle_t *cycle)
proc->pid = pid;
nxt_chan_read_close(proc->chan);
- nxt_chan_write_enable(nxt_thread(), proc->chan);
+ nxt_chan_write_enable(task, proc->chan);
- nxt_process_new_chan(cycle, proc);
+ nxt_process_new_chan(task, cycle, proc);
return NXT_OK;
}
}
static void
-nxt_master_process_sighup_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_master_process_sighup_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_cycle_t *cycle;
cycle = nxt_thread_cycle();
- nxt_log_error(NXT_LOG_NOTICE, thr->log, "signal %d (%s) recevied, %s",
- (int) (uintptr_t) obj, data,
- cycle->reconfiguring ? "ignored" : "reconfiguring");
+ nxt_log(task, NXT_LOG_NOTICE, "signal %d (%s) recevied, %s",
+ (int) (uintptr_t) obj, data,
+ cycle->reconfiguring ? "ignored" : "reconfiguring");
if (!cycle->reconfiguring) {
- (void) nxt_cycle_create(thr, cycle, nxt_master_process_new_cycle,
- cycle->config_name, 0);
+ (void) nxt_cycle_create(task->thread, task, cycle,
+ nxt_master_process_new_cycle,
+ cycle->config_name);
}
}
static void
-nxt_master_process_new_cycle(nxt_thread_t *thr, nxt_cycle_t *cycle)
+nxt_master_process_new_cycle(nxt_task_t *task, nxt_cycle_t *cycle)
{
- nxt_log_debug(thr->log, "new cycle");
+ nxt_thread_t *thr;
+
+ thr = task->thread;
+
+ nxt_debug(task, "new cycle");
/* A safe place to free the previous cycle. */
nxt_mem_pool_destroy(cycle->previous->mem_pool);
- switch (nxt_master_start_worker_processes(cycle)) {
+ switch (nxt_master_start_worker_processes(task, cycle)) {
case NXT_OK:
/*
@@ -240,7 +249,7 @@ nxt_master_process_new_cycle(nxt_thread_t *thr, nxt_cycle_t *cycle)
static void
-nxt_master_stop_previous_worker_processes(nxt_thread_t *thr, void *obj,
+nxt_master_stop_previous_worker_processes(nxt_task_t *task, void *obj,
void *data)
{
uint32_t generation;
@@ -259,7 +268,8 @@ nxt_master_stop_previous_worker_processes(nxt_thread_t *thr, void *obj,
for (i = 1; i < n; i++) {
if (proc[i].generation == generation) {
- (void) nxt_chan_write(proc[i].chan, NXT_CHAN_MSG_QUIT, -1, 0, NULL);
+ (void) nxt_chan_write(task, proc[i].chan, NXT_CHAN_MSG_QUIT,
+ -1, 0, NULL);
}
}
@@ -268,43 +278,43 @@ nxt_master_stop_previous_worker_processes(nxt_thread_t *thr, void *obj,
void
-nxt_master_stop_worker_processes(nxt_cycle_t *cycle)
+nxt_master_stop_worker_processes(nxt_task_t *task, nxt_cycle_t *cycle)
{
- nxt_process_chan_write(cycle, NXT_CHAN_MSG_QUIT, -1, 0, NULL);
+ nxt_process_chan_write(task, cycle, NXT_CHAN_MSG_QUIT, -1, 0, NULL);
}
static void
-nxt_master_process_sigterm_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_master_process_sigterm_handler(nxt_task_t *task, void *obj, void *data)
{
- nxt_log_debug(thr->log, "sigterm handler signo:%d (%s)",
- (int) (uintptr_t) obj, data);
+ nxt_debug(task, "sigterm handler signo:%d (%s)",
+ (int) (uintptr_t) obj, data);
/* TODO: fast exit. */
nxt_exiting = 1;
- nxt_cycle_quit(thr, NULL);
+ nxt_cycle_quit(task, NULL);
}
static void
-nxt_master_process_sigquit_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_master_process_sigquit_handler(nxt_task_t *task, void *obj, void *data)
{
- nxt_log_debug(thr->log, "sigquit handler signo:%d (%s)",
- (int) (uintptr_t) obj, data);
+ nxt_debug(task, "sigquit handler signo:%d (%s)",
+ (int) (uintptr_t) obj, data);
/* TODO: graceful exit. */
nxt_exiting = 1;
- nxt_cycle_quit(thr, NULL);
+ nxt_cycle_quit(task, NULL);
}
static void
-nxt_master_process_sigusr1_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_master_process_sigusr1_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_int_t ret;
nxt_uint_t n;
@@ -313,8 +323,8 @@ nxt_master_process_sigusr1_handler(nxt_thread_t *thr, void *obj, void *data)
nxt_array_t *new_files;
nxt_mem_pool_t *mp;
- nxt_log_error(NXT_LOG_NOTICE, thr->log, "signal %d (%s) recevied, %s",
- (int) (uintptr_t) obj, data, "log files rotation");
+ nxt_log(task, NXT_LOG_NOTICE, "signal %d (%s) recevied, %s",
+ (int) (uintptr_t) obj, data, "log files rotation");
mp = nxt_mem_pool_create(1024);
if (mp == NULL) {
@@ -358,7 +368,7 @@ nxt_master_process_sigusr1_handler(nxt_thread_t *thr, void *obj, void *data)
nxt_list_each(file, cycle->log_files) {
- nxt_process_chan_change_log_file(cycle, n, new_file[n].fd);
+ nxt_process_chan_change_log_file(task, cycle, n, new_file[n].fd);
/*
* The old log file descriptor must be closed at the moment
* when no other threads use it. dup2() allows to use the
@@ -394,7 +404,7 @@ fail:
static void
-nxt_master_process_sigusr2_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_master_process_sigusr2_handler(nxt_task_t *task, void *obj, void *data)
{
char **env;
nxt_int_t ret;
@@ -427,10 +437,10 @@ nxt_master_process_sigusr2_handler(nxt_thread_t *thr, void *obj, void *data)
ignore = 1;
}
- nxt_log_error(NXT_LOG_NOTICE, thr->log,
- "signal %d (%s) recevied, %s, parent pid: %PI",
- (int) (uintptr_t) obj, data,
- ignore ? "ignored" : "online binary file upgrade", ppid);
+ nxt_log(task, NXT_LOG_NOTICE,
+ "signal %d (%s) recevied, %s, parent pid: %PI",
+ (int) (uintptr_t) obj, data,
+ ignore ? "ignored" : "online binary file upgrade", ppid);
if (ignore) {
return;
@@ -552,14 +562,14 @@ nxt_master_process_upgrade_environment_create(nxt_cycle_t *cycle)
static void
-nxt_master_process_sigchld_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_master_process_sigchld_handler(nxt_task_t *task, void *obj, void *data)
{
int status;
nxt_err_t err;
nxt_pid_t pid;
- nxt_log_debug(thr->log, "sigchld handler signo:%d (%s)",
- (int) (uintptr_t) obj, data);
+ nxt_debug(task, "sigchld handler signo:%d (%s)",
+ (int) (uintptr_t) obj, data);
for ( ;; ) {
pid = waitpid(-1, &status, WNOHANG);
@@ -575,12 +585,12 @@ nxt_master_process_sigchld_handler(nxt_thread_t *thr, void *obj, void *data)
continue;
default:
- nxt_log_alert(thr->log, "waitpid() failed: %E", err);
+ nxt_log(task, NXT_LOG_CRIT, "waitpid() failed: %E", err);
return;
}
}
- nxt_log_debug(thr->log, "waitpid(): %PI", pid);
+ nxt_debug(task, "waitpid(): %PI", pid);
if (pid == 0) {
return;
@@ -588,27 +598,26 @@ nxt_master_process_sigchld_handler(nxt_thread_t *thr, void *obj, void *data)
if (WTERMSIG(status)) {
#ifdef WCOREDUMP
- nxt_log_alert(thr->log, "process %PI exited on signal %d%s",
- pid, WTERMSIG(status),
- WCOREDUMP(status) ? " (core dumped)" : "");
+ nxt_log(task, NXT_LOG_CRIT, "process %PI exited on signal %d%s",
+ pid, WTERMSIG(status),
+ WCOREDUMP(status) ? " (core dumped)" : "");
#else
- nxt_log_alert(thr->log, "process %PI exited on signal %d",
- pid, WTERMSIG(status));
+ nxt_log(task, NXT_LOG_CRIT, "process %PI exited on signal %d",
+ pid, WTERMSIG(status));
#endif
} else {
- nxt_log_error(NXT_LOG_NOTICE, thr->log,
- "process %PI exited with code %d",
- pid, WEXITSTATUS(status));
+ nxt_trace(task, "process %PI exited with code %d",
+ pid, WEXITSTATUS(status));
}
- nxt_master_cleanup_worker_process(thr, pid);
+ nxt_master_cleanup_worker_process(task, pid);
}
}
static void
-nxt_master_cleanup_worker_process(nxt_thread_t *thr, nxt_pid_t pid)
+nxt_master_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid)
{
nxt_uint_t i, n, generation;
nxt_cycle_t *cycle;
@@ -634,14 +643,14 @@ nxt_master_cleanup_worker_process(nxt_thread_t *thr, nxt_pid_t pid)
nxt_array_remove(cycle->processes, &proc[i]);
if (nxt_exiting) {
- nxt_log_debug(thr->log, "processes %d", n);
+ nxt_debug(task, "processes %d", n);
if (n == 2) {
- nxt_cycle_quit(thr, cycle);
+ nxt_cycle_quit(task, cycle);
}
} else if (generation == cycle->process_generation) {
- (void) nxt_master_create_worker_process(cycle);
+ (void) nxt_master_create_worker_process(task, cycle);
}
return;
diff --git a/src/nxt_master_process.h b/src/nxt_master_process.h
index 8018c6b8..ce40455e 100644
--- a/src/nxt_master_process.h
+++ b/src/nxt_master_process.h
@@ -8,8 +8,9 @@
#define _NXT_UNIX_MASTER_PROCESS_H_INCLUDED_
-nxt_int_t nxt_master_process_start(nxt_thread_t *thr, nxt_cycle_t *cycle);
-void nxt_master_stop_worker_processes(nxt_cycle_t *cycle);
+nxt_int_t nxt_master_process_start(nxt_thread_t *thr, nxt_task_t *task,
+ nxt_cycle_t *cycle);
+void nxt_master_stop_worker_processes(nxt_task_t *task, nxt_cycle_t *cycle);
void nxt_worker_process_start(void *data);
diff --git a/src/nxt_openssl.c b/src/nxt_openssl.c
index fcdd2876..3903b5a7 100644
--- a/src/nxt_openssl.c
+++ b/src/nxt_openssl.c
@@ -22,19 +22,18 @@ typedef struct {
static nxt_int_t nxt_openssl_server_init(nxt_ssltls_conf_t *conf);
-static void nxt_openssl_conn_init(nxt_thread_t *thr, nxt_ssltls_conf_t *conf,
+static void nxt_openssl_conn_init(nxt_task_t *task, nxt_ssltls_conf_t *conf,
nxt_event_conn_t *c);
static void nxt_openssl_session_cleanup(void *data);
-static void nxt_openssl_conn_handshake(nxt_thread_t *thr, void *obj,
+static void nxt_openssl_conn_handshake(nxt_task_t *task, void *obj, void *data);
+static void nxt_openssl_conn_io_read(nxt_task_t *task, void *obj, void *data);
+static void nxt_openssl_conn_io_shutdown(nxt_task_t *task, void *obj,
void *data);
-static void nxt_openssl_conn_io_read(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_openssl_conn_io_shutdown(nxt_thread_t *thr, void *obj,
- void *data);
-static ssize_t nxt_openssl_conn_io_write_chunk(nxt_thread_t *thr,
- nxt_event_conn_t *c, nxt_buf_t *b, size_t limit);
+static ssize_t nxt_openssl_conn_io_write_chunk(nxt_event_conn_t *c,
+ nxt_buf_t *b, size_t limit);
static ssize_t nxt_openssl_conn_io_send(nxt_event_conn_t *c, void *buf,
size_t size);
-static nxt_int_t nxt_openssl_conn_test_error(nxt_thread_t *thr,
+static nxt_int_t nxt_openssl_conn_test_error(nxt_task_t *task,
nxt_event_conn_t *c, int ret, nxt_err_t sys_err,
nxt_work_handler_t handler);
static void nxt_cdecl nxt_openssl_conn_error(nxt_event_conn_t *c, nxt_err_t err,
@@ -250,7 +249,7 @@ fail:
static void
-nxt_openssl_conn_init(nxt_thread_t *thr, nxt_ssltls_conf_t *conf,
+nxt_openssl_conn_init(nxt_task_t *task, nxt_ssltls_conf_t *conf,
nxt_event_conn_t *c)
{
int ret;
@@ -305,13 +304,14 @@ nxt_openssl_conn_init(nxt_thread_t *thr, nxt_ssltls_conf_t *conf,
c->io = &nxt_openssl_event_conn_io;
c->sendfile = NXT_CONN_SENDFILE_OFF;
- nxt_openssl_conn_handshake(thr, c, c->socket.data);
+ nxt_openssl_conn_handshake(task, c, c->socket.data);
return;
fail:
- nxt_event_conn_io_handle(thr, c->read_work_queue,
- c->read_state->error_handler, c, c->socket.data);
+ nxt_event_conn_io_handle(task->thread, c->read_work_queue,
+ c->read_state->error_handler,
+ task, c, c->socket.data);
}
@@ -331,7 +331,7 @@ nxt_openssl_session_cleanup(void *data)
static void
-nxt_openssl_conn_handshake(nxt_thread_t *thr, void *obj, void *data)
+nxt_openssl_conn_handshake(nxt_task_t *task, void *obj, void *data)
{
int ret;
nxt_int_t n;
@@ -342,7 +342,7 @@ nxt_openssl_conn_handshake(nxt_thread_t *thr, void *obj, void *data)
c = obj;
ssltls = c->u.ssltls;
- nxt_log_debug(thr->log, "openssl conn handshake: %d", ssltls->times);
+ nxt_debug(task, "openssl conn handshake: %d", ssltls->times);
/* "ssltls->times == 1" is suitable to run SSL_do_handshake() in job. */
@@ -350,26 +350,26 @@ nxt_openssl_conn_handshake(nxt_thread_t *thr, void *obj, void *data)
err = (ret <= 0) ? nxt_socket_errno : 0;
- nxt_thread_time_debug_update(thr);
+ nxt_thread_time_debug_update(task->thread);
- nxt_log_debug(thr->log, "SSL_do_handshake(%d): %d err:%d",
- c->socket.fd, ret, err);
+ nxt_debug(task, "SSL_do_handshake(%d): %d err:%d", c->socket.fd, ret, err);
if (ret > 0) {
/* ret == 1, the handshake was successfully completed. */
- nxt_openssl_conn_io_read(thr, c, data);
+ nxt_openssl_conn_io_read(task, c, data);
return;
}
- n = nxt_openssl_conn_test_error(thr, c, ret, err,
+ n = nxt_openssl_conn_test_error(task, c, ret, err,
nxt_openssl_conn_handshake);
if (n == NXT_ERROR) {
nxt_openssl_conn_error(c, err, "SSL_do_handshake(%d) failed",
c->socket.fd);
- nxt_event_conn_io_handle(thr, c->read_work_queue,
- c->read_state->error_handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->read_work_queue,
+ c->read_state->error_handler,
+ task, c, data);
} else if (ssltls->ssl_error == SSL_ERROR_WANT_READ && ssltls->times < 2) {
ssltls->times++;
@@ -378,7 +378,7 @@ nxt_openssl_conn_handshake(nxt_thread_t *thr, void *obj, void *data)
static void
-nxt_openssl_conn_io_read(nxt_thread_t *thr, void *obj, void *data)
+nxt_openssl_conn_io_read(nxt_task_t *task, void *obj, void *data)
{
int ret;
nxt_buf_t *b;
@@ -390,7 +390,7 @@ nxt_openssl_conn_io_read(nxt_thread_t *thr, void *obj, void *data)
c = obj;
- nxt_log_debug(thr->log, "openssl conn read");
+ nxt_debug(task, "openssl conn read");
handler = c->read_state->ready_handler;
b = c->read;
@@ -404,9 +404,9 @@ nxt_openssl_conn_io_read(nxt_thread_t *thr, void *obj, void *data)
err = (ret <= 0) ? nxt_socket_errno : 0;
- nxt_log_debug(thr->log, "SSL_read(%d, %p, %uz): %d err:%d",
- c->socket.fd, b->mem.free, b->mem.end - b->mem.free,
- ret, err);
+ nxt_debug(task, "SSL_read(%d, %p, %uz): %d err:%d",
+ c->socket.fd, b->mem.free, b->mem.end - b->mem.free,
+ ret, err);
if (ret > 0) {
/* c->socket.read_ready is kept. */
@@ -414,7 +414,7 @@ nxt_openssl_conn_io_read(nxt_thread_t *thr, void *obj, void *data)
handler = c->read_state->ready_handler;
} else {
- n = nxt_openssl_conn_test_error(thr, c, ret, err,
+ n = nxt_openssl_conn_test_error(task, c, ret, err,
nxt_openssl_conn_io_read);
if (nxt_fast_path(n != NXT_ERROR)) {
@@ -429,17 +429,17 @@ nxt_openssl_conn_io_read(nxt_thread_t *thr, void *obj, void *data)
}
}
- nxt_event_conn_io_handle(thr, c->read_work_queue, handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->read_work_queue, handler,
+ task, c, data);
}
static ssize_t
-nxt_openssl_conn_io_write_chunk(nxt_thread_t *thr, nxt_event_conn_t *c,
- nxt_buf_t *b, size_t limit)
+nxt_openssl_conn_io_write_chunk(nxt_event_conn_t *c, nxt_buf_t *b, size_t limit)
{
nxt_openssl_conn_t *ssltls;
- nxt_log_debug(thr->log, "openssl conn write chunk");
+ nxt_debug(c->socket.task, "openssl conn write chunk");
ssltls = c->u.ssltls;
@@ -474,7 +474,7 @@ nxt_openssl_conn_io_send(nxt_event_conn_t *c, void *buf, size_t size)
return ret;
}
- n = nxt_openssl_conn_test_error(nxt_thread(), c, ret, err,
+ n = nxt_openssl_conn_test_error(c->socket.task, c, ret, err,
nxt_event_conn_io_write);
if (n == NXT_ERROR) {
@@ -487,7 +487,7 @@ nxt_openssl_conn_io_send(nxt_event_conn_t *c, void *buf, size_t size)
static void
-nxt_openssl_conn_io_shutdown(nxt_thread_t *thr, void *obj, void *data)
+nxt_openssl_conn_io_shutdown(nxt_task_t *task, void *obj, void *data)
{
int ret, mode;
SSL *s;
@@ -500,7 +500,7 @@ nxt_openssl_conn_io_shutdown(nxt_thread_t *thr, void *obj, void *data)
c = obj;
- nxt_log_debug(thr->log, "openssl conn shutdown");
+ nxt_debug(task, "openssl conn shutdown");
ssltls = c->u.ssltls;
s = ssltls->session;
@@ -533,8 +533,8 @@ nxt_openssl_conn_io_shutdown(nxt_thread_t *thr, void *obj, void *data)
err = (ret <= 0) ? nxt_socket_errno : 0;
- nxt_log_debug(thr->log, "SSL_shutdown(%d, %d, %b): %d err:%d",
- c->socket.fd, mode, quiet, ret, err);
+ nxt_debug(task, "SSL_shutdown(%d, %d, %b): %d err:%d",
+ c->socket.fd, mode, quiet, ret, err);
if (ret > 0) {
/* ret == 1, the shutdown was successfully completed. */
@@ -565,7 +565,7 @@ nxt_openssl_conn_io_shutdown(nxt_thread_t *thr, void *obj, void *data)
break;
}
- n = nxt_openssl_conn_test_error(thr, c, ret, err,
+ n = nxt_openssl_conn_test_error(task, c, ret, err,
nxt_openssl_conn_io_shutdown);
if (nxt_fast_path(n == 0)) {
@@ -574,7 +574,7 @@ nxt_openssl_conn_io_shutdown(nxt_thread_t *thr, void *obj, void *data)
if (n != NXT_ERROR) { /* n == NXT_AGAIN */
c->socket.error_handler = c->read_state->error_handler;
- nxt_event_timer_add(thr->engine, &c->read_timer, 5000);
+ nxt_event_timer_add(task->thread->engine, &c->read_timer, 5000);
return;
}
@@ -584,12 +584,13 @@ nxt_openssl_conn_io_shutdown(nxt_thread_t *thr, void *obj, void *data)
done:
- nxt_event_conn_io_handle(thr, c->write_work_queue, handler, c, data);
+ nxt_event_conn_io_handle(task->thread, c->write_work_queue, handler,
+ task, c, data);
}
static nxt_int_t
-nxt_openssl_conn_test_error(nxt_thread_t *thr, nxt_event_conn_t *c, int ret,
+nxt_openssl_conn_test_error(nxt_task_t *task, nxt_event_conn_t *c, int ret,
nxt_err_t sys_err, nxt_work_handler_t handler)
{
u_long lib_err;
@@ -605,25 +606,25 @@ nxt_openssl_conn_test_error(nxt_thread_t *thr, nxt_event_conn_t *c, int ret,
switch (ssltls->ssl_error) {
case SSL_ERROR_WANT_READ:
- nxt_event_fd_block_write(thr->engine, &c->socket);
+ nxt_event_fd_block_write(task->thread->engine, &c->socket);
c->socket.read_ready = 0;
c->socket.read_handler = handler;
if (nxt_event_fd_is_disabled(c->socket.read)) {
- nxt_event_fd_enable_read(thr->engine, &c->socket);
+ nxt_event_fd_enable_read(task->thread->engine, &c->socket);
}
return NXT_AGAIN;
case SSL_ERROR_WANT_WRITE:
- nxt_event_fd_block_read(thr->engine, &c->socket);
+ nxt_event_fd_block_read(task->thread->engine, &c->socket);
c->socket.write_ready = 0;
c->socket.write_handler = handler;
if (nxt_event_fd_is_disabled(c->socket.write)) {
- nxt_event_fd_enable_write(thr->engine, &c->socket);
+ nxt_event_fd_enable_write(task->thread->engine, &c->socket);
}
return NXT_AGAIN;
@@ -632,7 +633,7 @@ nxt_openssl_conn_test_error(nxt_thread_t *thr, nxt_event_conn_t *c, int ret,
lib_err = ERR_peek_error();
- nxt_log_debug(c->socket.log, "ERR_peek_error(): %l", lib_err);
+ nxt_debug(task, "ERR_peek_error(): %l", lib_err);
if (sys_err != 0 || lib_err != 0) {
return NXT_ERROR;
@@ -655,7 +656,8 @@ nxt_openssl_conn_test_error(nxt_thread_t *thr, nxt_event_conn_t *c, int ret,
handler = c->write_state->close_handler;
}
- nxt_event_conn_io_handle(thr, wq, handler, c, c->socket.data);
+ nxt_event_conn_io_handle(task->thread, wq, handler,
+ task, c, c->socket.data);
return 0;
diff --git a/src/nxt_poll.c b/src/nxt_poll.c
index 43cebe38..2cc0200b 100644
--- a/src/nxt_poll.c
+++ b/src/nxt_poll.c
@@ -58,7 +58,7 @@ static nxt_int_t nxt_poll_set_change(nxt_thread_t *thr,
nxt_poll_event_set_t *ps, nxt_poll_change_t *ch);
static nxt_int_t nxt_poll_set_delete(nxt_thread_t *thr,
nxt_poll_event_set_t *ps, nxt_poll_change_t *ch);
-static void nxt_poll_set_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
+static void nxt_poll_set_poll(nxt_task_t *task, nxt_event_set_t *event_set,
nxt_msec_t timeout);
static nxt_poll_hash_entry_t *nxt_poll_fd_hash_get(nxt_poll_event_set_t *ps,
nxt_fd_t fd);
@@ -398,7 +398,7 @@ nxt_poll_commit_changes(nxt_thread_t *thr, nxt_poll_event_set_t *ps)
}
nxt_thread_work_queue_add(thr, &thr->work_queue.main,
- ev->error_handler, ev, ev->data, ev->log);
+ ev->error_handler, ev->task, ev, ev->data);
ret = NXT_ERROR;
@@ -534,7 +534,7 @@ nxt_poll_set_delete(nxt_thread_t *thr, nxt_poll_event_set_t *ps,
static void
-nxt_poll_set_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
+nxt_poll_set_poll(nxt_task_t *task, nxt_event_set_t *event_set,
nxt_msec_t timeout)
{
int nevents;
@@ -556,19 +556,19 @@ nxt_poll_set_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
}
}
- nxt_log_debug(thr->log, "poll() events:%ui timeout:%M", ps->nfds, timeout);
+ nxt_debug(task, "poll() events:%ui timeout:%M", ps->nfds, timeout);
nevents = poll(ps->poll_set, ps->nfds, timeout);
err = (nevents == -1) ? nxt_errno : 0;
- nxt_thread_time_update(thr);
+ nxt_thread_time_update(task->thread);
- nxt_log_debug(thr->log, "poll(): %d", nevents);
+ nxt_debug(task, "poll(): %d", nevents);
if (nevents == -1) {
level = (err == NXT_EINTR) ? NXT_LOG_INFO : NXT_LOG_ALERT;
- nxt_log_error(level, thr->log, "poll() failed %E", err);
+ nxt_log(task, level, "poll() failed %E", err);
return;
}
@@ -586,9 +586,9 @@ nxt_poll_set_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
phe = nxt_poll_fd_hash_get(ps, fd);
if (nxt_slow_path(phe == NULL)) {
- nxt_log_alert(thr->log,
- "poll() returned invalid fd:%d ev:%04Xd rev:%04uXi",
- fd, pfd->events, events);
+ nxt_log(task, NXT_LOG_CRIT,
+ "poll() returned invalid fd:%d ev:%04Xd rev:%04uXi",
+ fd, pfd->events, events);
/* Mark the poll entry to ignore it by the kernel. */
pfd->fd = -1;
@@ -597,18 +597,21 @@ nxt_poll_set_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
ev = phe->event;
- nxt_log_debug(ev->log, "poll: fd:%d ev:%04uXi rd:%d %wr:%d",
- fd, events, ev->read, ev->write);
+ nxt_debug(ev->task, "poll: fd:%d ev:%04uXi rd:%d %wr:%d",
+ fd, events, ev->read, ev->write);
if (nxt_slow_path((events & POLLNVAL) != 0)) {
- nxt_log_alert(ev->log, "poll() error fd:%d ev:%04Xd rev:%04uXi",
- fd, pfd->events, events);
+ nxt_log(ev->task, NXT_LOG_CRIT,
+ "poll() error fd:%d ev:%04Xd rev:%04uXi",
+ fd, pfd->events, events);
/* Mark the poll entry to ignore it by the kernel. */
pfd->fd = -1;
- nxt_thread_work_queue_add(thr, &thr->work_queue.main,
- ev->error_handler, ev, ev->data, ev->log);
+ nxt_thread_work_queue_add(task->thread,
+ &task->thread->work_queue.main,
+ ev->error_handler,
+ ev->task, ev, ev->data);
goto next;
}
@@ -650,8 +653,8 @@ nxt_poll_set_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
nxt_poll_change(event_set, ev, NXT_POLL_DELETE, 0);
}
- nxt_thread_work_queue_add(thr, ev->read_work_queue,
- ev->read_handler, ev, ev->data, ev->log);
+ nxt_thread_work_queue_add(task->thread, ev->read_work_queue,
+ ev->read_handler, ev->task, ev, ev->data);
}
if ((events & POLLOUT) || (error && ev->write_handler != NULL)) {
@@ -662,8 +665,9 @@ nxt_poll_set_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
nxt_poll_change(event_set, ev, NXT_POLL_DELETE, 0);
}
- nxt_thread_work_queue_add(thr, ev->write_work_queue,
- ev->write_handler, ev, ev->data, ev->log);
+ nxt_thread_work_queue_add(task->thread, ev->write_work_queue,
+ ev->write_handler,
+ ev->task, ev, ev->data);
}
next:
diff --git a/src/nxt_process_chan.c b/src/nxt_process_chan.c
index 4fcc1a15..2986f62b 100644
--- a/src/nxt_process_chan.c
+++ b/src/nxt_process_chan.c
@@ -9,9 +9,9 @@
#include <nxt_process_chan.h>
-static void nxt_process_chan_handler(nxt_thread_t *thr,
+static void nxt_process_chan_handler(nxt_task_t *task,
nxt_chan_recv_msg_t *msg);
-static void nxt_process_new_chan_buf_completion(nxt_thread_t *thr, void *obj,
+static void nxt_process_new_chan_buf_completion(nxt_task_t *task, void *obj,
void *data);
@@ -25,13 +25,13 @@ nxt_process_chan_create(nxt_thread_t *thr, nxt_process_chan_t *proc,
proc->chan->data = handlers;
nxt_chan_write_close(proc->chan);
- nxt_chan_read_enable(thr, proc->chan);
+ nxt_chan_read_enable(&thr->engine->task, proc->chan);
}
void
-nxt_process_chan_write(nxt_cycle_t *cycle, nxt_uint_t type, nxt_fd_t fd,
- uint32_t stream, nxt_buf_t *b)
+nxt_process_chan_write(nxt_task_t *task, nxt_cycle_t *cycle, nxt_uint_t type,
+ nxt_fd_t fd, uint32_t stream, nxt_buf_t *b)
{
nxt_uint_t i, n;
nxt_process_chan_t *proc;
@@ -41,42 +41,43 @@ nxt_process_chan_write(nxt_cycle_t *cycle, nxt_uint_t type, nxt_fd_t fd,
for (i = 0; i < n; i++) {
if (nxt_pid != proc[i].pid) {
- (void) nxt_chan_write(proc[i].chan, type, fd, stream, b);
+ (void) nxt_chan_write(task, proc[i].chan, type, fd, stream, b);
}
}
}
static void
-nxt_process_chan_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg)
+nxt_process_chan_handler(nxt_task_t *task, nxt_chan_recv_msg_t *msg)
{
nxt_process_chan_handler_t *handlers;
if (nxt_fast_path(msg->type <= NXT_CHAN_MSG_MAX)) {
- nxt_log_debug(thr->log, "chan %d: message type:%uD",
- msg->chan->socket.fd, msg->type);
+ nxt_debug(task, "chan %d: message type:%uD",
+ msg->chan->socket.fd, msg->type);
handlers = msg->chan->data;
- handlers[msg->type](thr, msg);
+ handlers[msg->type](task, msg);
return;
}
- nxt_log_alert(thr->log, "chan %d: unknown message type:%uD",
- msg->chan->socket.fd, msg->type);
+ nxt_log(task, NXT_LOG_CRIT, "chan %d: unknown message type:%uD",
+ msg->chan->socket.fd, msg->type);
}
void
-nxt_process_chan_quit_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg)
+nxt_process_chan_quit_handler(nxt_task_t *task, nxt_chan_recv_msg_t *msg)
{
- nxt_cycle_quit(thr, NULL);
+ nxt_cycle_quit(task, NULL);
}
void
-nxt_process_new_chan(nxt_cycle_t *cycle, nxt_process_chan_t *proc)
+nxt_process_new_chan(nxt_task_t *task, nxt_cycle_t *cycle,
+ nxt_process_chan_t *proc)
{
nxt_buf_t *b;
nxt_uint_t i, n;
@@ -116,14 +117,14 @@ nxt_process_new_chan(nxt_cycle_t *cycle, nxt_process_chan_t *proc)
new_chan->max_size = p[i].chan->max_size;
new_chan->max_share = p[i].chan->max_share;
- (void) nxt_chan_write(p[i].chan, NXT_CHAN_MSG_NEW_CHAN,
+ (void) nxt_chan_write(task, p[i].chan, NXT_CHAN_MSG_NEW_CHAN,
proc->chan->socket.fd, 0, b);
}
}
static void
-nxt_process_new_chan_buf_completion(nxt_thread_t *thr, void *obj, void *data)
+nxt_process_new_chan_buf_completion(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b;
nxt_chan_t *chan;
@@ -138,7 +139,7 @@ nxt_process_new_chan_buf_completion(nxt_thread_t *thr, void *obj, void *data)
void
-nxt_process_chan_new_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg)
+nxt_process_chan_new_handler(nxt_task_t *task, nxt_chan_recv_msg_t *msg)
{
nxt_chan_t *chan;
nxt_cycle_t *cycle;
@@ -162,8 +163,8 @@ nxt_process_chan_new_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg)
new_chan = (nxt_proc_msg_new_chan_t *) msg->buf->mem.pos;
msg->buf->mem.pos = msg->buf->mem.free;
- nxt_log_debug(thr->log, "new chan %d received for process %PI engine %uD",
- msg->fd, new_chan->pid, new_chan->engine);
+ nxt_debug(task, "new chan %d received for process %PI engine %uD",
+ msg->fd, new_chan->pid, new_chan->engine);
proc->pid = new_chan->pid;
proc->engine = new_chan->engine;
@@ -172,13 +173,13 @@ nxt_process_chan_new_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg)
chan->max_share = new_chan->max_share;
/* A read chan is not passed at all. */
- nxt_chan_write_enable(thr, chan);
+ nxt_chan_write_enable(task, chan);
}
void
-nxt_process_chan_change_log_file(nxt_cycle_t *cycle, nxt_uint_t slot,
- nxt_fd_t fd)
+nxt_process_chan_change_log_file(nxt_task_t *task, nxt_cycle_t *cycle,
+ nxt_uint_t slot, nxt_fd_t fd)
{
nxt_buf_t *b;
nxt_uint_t i, n;
@@ -206,13 +207,14 @@ nxt_process_chan_change_log_file(nxt_cycle_t *cycle, nxt_uint_t slot,
*(nxt_uint_t *) b->mem.pos = slot;
b->mem.free += sizeof(nxt_uint_t);
- (void) nxt_chan_write(p[i].chan, NXT_CHAN_MSG_CHANGE_FILE, fd, 0, b);
+ (void) nxt_chan_write(task, p[i].chan, NXT_CHAN_MSG_CHANGE_FILE,
+ fd, 0, b);
}
}
void
-nxt_process_chan_change_log_file_handler(nxt_thread_t *thr,
+nxt_process_chan_change_log_file_handler(nxt_task_t *task,
nxt_chan_recv_msg_t *msg)
{
nxt_buf_t *b;
@@ -227,7 +229,7 @@ nxt_process_chan_change_log_file_handler(nxt_thread_t *thr,
log_file = nxt_list_elt(cycle->log_files, slot);
- nxt_log_debug(thr->log, "change log file %FD:%FD", msg->fd, log_file->fd);
+ nxt_debug(task, "change log file %FD:%FD", msg->fd, log_file->fd);
/*
* The old log file descriptor must be closed at the moment when no
@@ -244,20 +246,20 @@ nxt_process_chan_change_log_file_handler(nxt_thread_t *thr,
void
-nxt_process_chan_data_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg)
+nxt_process_chan_data_handler(nxt_task_t *task, nxt_chan_recv_msg_t *msg)
{
nxt_buf_t *b;
b = msg->buf;
- nxt_log_debug(thr->log, "data: %*s", b->mem.free - b->mem.pos, b->mem.pos);
+ nxt_debug(task, "data: %*s", b->mem.free - b->mem.pos, b->mem.pos);
b->mem.pos = b->mem.free;
}
void
-nxt_process_chan_empty_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg)
+nxt_process_chan_empty_handler(nxt_task_t *task, nxt_chan_recv_msg_t *msg)
{
- nxt_log_debug(thr->log, "chan empty handler");
+ nxt_debug(task, "chan empty handler");
}
diff --git a/src/nxt_process_chan.h b/src/nxt_process_chan.h
index a073e3dd..18ff7be3 100644
--- a/src/nxt_process_chan.h
+++ b/src/nxt_process_chan.h
@@ -44,25 +44,25 @@ typedef union {
} nxt_process_chan_data_t;
-typedef void (*nxt_process_chan_handler_t)(nxt_thread_t *thr,
+typedef void (*nxt_process_chan_handler_t)(nxt_task_t *task,
nxt_chan_recv_msg_t *msg);
void nxt_process_chan_create(nxt_thread_t *thr, nxt_process_chan_t *proc,
nxt_process_chan_handler_t *handlers);
-void nxt_process_chan_write(nxt_cycle_t *cycle, nxt_uint_t type,
- nxt_fd_t fd, uint32_t stream, nxt_buf_t *b);
-void nxt_process_new_chan(nxt_cycle_t *cycle, nxt_process_chan_t *proc);
-void nxt_process_chan_change_log_file(nxt_cycle_t *cycle, nxt_uint_t slot,
- nxt_fd_t fd);
-
-void nxt_process_chan_quit_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg);
-void nxt_process_chan_new_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg);
-void nxt_process_chan_change_log_file_handler(nxt_thread_t *thr,
- nxt_chan_recv_msg_t *msg);
-void nxt_process_chan_data_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg);
-void nxt_process_chan_empty_handler(nxt_thread_t *thr,
+void nxt_process_chan_write(nxt_task_t *task, nxt_cycle_t *cycle,
+ nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_buf_t *b);
+void nxt_process_new_chan(nxt_task_t *task, nxt_cycle_t *cycle,
+ nxt_process_chan_t *proc);
+void nxt_process_chan_change_log_file(nxt_task_t *task, nxt_cycle_t *cycle,
+ nxt_uint_t slot, nxt_fd_t fd);
+
+void nxt_process_chan_quit_handler(nxt_task_t *task, nxt_chan_recv_msg_t *msg);
+void nxt_process_chan_new_handler(nxt_task_t *task, nxt_chan_recv_msg_t *msg);
+void nxt_process_chan_change_log_file_handler(nxt_task_t *task,
nxt_chan_recv_msg_t *msg);
+void nxt_process_chan_data_handler(nxt_task_t *task, nxt_chan_recv_msg_t *msg);
+void nxt_process_chan_empty_handler(nxt_task_t *task, nxt_chan_recv_msg_t *msg);
#endif /* _NXT_PROCESS_CHAN_H_INCLUDED_ */
diff --git a/src/nxt_select.c b/src/nxt_select.c
index a9713ac0..a2982d2f 100644
--- a/src/nxt_select.c
+++ b/src/nxt_select.c
@@ -16,8 +16,7 @@ static void nxt_select_enable_read(nxt_event_set_t *event_set,
nxt_event_fd_t *ev);
static void nxt_select_enable_write(nxt_event_set_t *event_set,
nxt_event_fd_t *ev);
-static void nxt_select_error_handler(nxt_thread_t *thr, void *obj,
- void *data);
+static void nxt_select_error_handler(nxt_task_t *task, void *obj, void *data);
static void nxt_select_disable_read(nxt_event_set_t *event_set,
nxt_event_fd_t *ev);
static void nxt_select_disable_write(nxt_event_set_t *event_set,
@@ -30,7 +29,7 @@ static void nxt_select_oneshot_read(nxt_event_set_t *event_set,
nxt_event_fd_t *ev);
static void nxt_select_oneshot_write(nxt_event_set_t *event_set,
nxt_event_fd_t *ev);
-static void nxt_select_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
+static void nxt_select_poll(nxt_task_t *task, nxt_event_set_t *event_set,
nxt_msec_t timeout);
@@ -144,7 +143,7 @@ nxt_select_enable_read(nxt_event_set_t *event_set, nxt_event_fd_t *ev)
thr = nxt_thread();
nxt_thread_work_queue_add(thr, &thr->work_queue.main,
nxt_select_error_handler,
- ev, ev->data, ev->log);
+ ev->task, ev, ev->data);
return;
}
@@ -177,7 +176,7 @@ nxt_select_enable_write(nxt_event_set_t *event_set, nxt_event_fd_t *ev)
thr = nxt_thread();
nxt_thread_work_queue_add(thr, &thr->work_queue.main,
nxt_select_error_handler,
- ev, ev->data, ev->log);
+ ev->task, ev, ev->data);
return;
}
@@ -194,7 +193,7 @@ nxt_select_enable_write(nxt_event_set_t *event_set, nxt_event_fd_t *ev)
static void
-nxt_select_error_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_select_error_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_event_fd_t *ev;
@@ -203,7 +202,7 @@ nxt_select_error_handler(nxt_thread_t *thr, void *obj, void *data)
ev->read = NXT_EVENT_INACTIVE;
ev->write = NXT_EVENT_INACTIVE;
- ev->error_handler(thr, ev, data);
+ ev->error_handler(task, ev, data);
}
@@ -296,7 +295,7 @@ nxt_select_oneshot_write(nxt_event_set_t *event_set, nxt_event_fd_t *ev)
static void
-nxt_select_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
+nxt_select_poll(nxt_task_t *task, nxt_event_set_t *event_set,
nxt_msec_t timeout)
{
int nevents, nfds, found;
@@ -333,20 +332,20 @@ nxt_select_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
nfds = ss->nfds + 1;
- nxt_log_debug(thr->log, "select() nfds:%d timeout:%M", nfds, timeout);
+ nxt_debug(task, "select() nfds:%d timeout:%M", nfds, timeout);
nevents = select(nfds, &ss->work_read_fd_set, &ss->work_write_fd_set,
NULL, tp);
err = (nevents == -1) ? nxt_errno : 0;
- nxt_thread_time_update(thr);
+ nxt_thread_time_update(task->thread);
- nxt_log_debug(thr->log, "select(): %d", nevents);
+ nxt_debug(task, "select(): %d", nevents);
if (nevents == -1) {
level = (err == NXT_EINTR) ? NXT_LOG_INFO : NXT_LOG_ALERT;
- nxt_log_error(level, thr->log, "select() failed %E", err);
+ nxt_log(task, level, "select() failed %E", err);
return;
}
@@ -357,8 +356,8 @@ nxt_select_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
if (FD_ISSET(fd, &ss->work_read_fd_set)) {
ev = ss->events[fd];
- nxt_log_debug(ev->log, "select() fd:%ui read rd:%d wr:%d",
- fd, ev->read, ev->write);
+ nxt_debug(ev->task, "select() fd:%ui read rd:%d wr:%d",
+ fd, ev->read, ev->write);
ev->read_ready = 1;
@@ -366,8 +365,8 @@ nxt_select_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
nxt_select_disable_read(event_set, ev);
}
- nxt_thread_work_queue_add(thr, ev->read_work_queue,
- ev->read_handler, ev, ev->data, ev->log);
+ nxt_thread_work_queue_add(task->thread, ev->read_work_queue,
+ ev->read_handler, ev->task, ev, ev->data);
found = 1;
}
@@ -383,8 +382,9 @@ nxt_select_poll(nxt_thread_t *thr, nxt_event_set_t *event_set,
nxt_select_disable_write(event_set, ev);
}
- nxt_thread_work_queue_add(thr, ev->write_work_queue,
- ev->write_handler, ev, ev->data, ev->log);
+ nxt_thread_work_queue_add(task->thread, ev->write_work_queue,
+ ev->write_handler,
+ ev->task, ev, ev->data);
found = 1;
}
diff --git a/src/nxt_sendbuf.c b/src/nxt_sendbuf.c
index d473a29b..e8a4c190 100644
--- a/src/nxt_sendbuf.c
+++ b/src/nxt_sendbuf.c
@@ -12,7 +12,7 @@ static nxt_bool_t nxt_sendbuf_copy(nxt_buf_mem_t *bm, nxt_buf_t *b,
nxt_uint_t
-nxt_sendbuf_mem_coalesce(nxt_sendbuf_coalesce_t *sb)
+nxt_sendbuf_mem_coalesce(nxt_task_t *task, nxt_sendbuf_coalesce_t *sb)
{
u_char *last;
size_t size, total;
@@ -57,9 +57,9 @@ nxt_sendbuf_mem_coalesce(nxt_sendbuf_coalesce_t *sb)
nxt_iobuf_add(&sb->iobuf[n], size);
}
- nxt_thread_log_debug("sendbuf: %ui, %p, %uz", n,
- nxt_iobuf_data(&sb->iobuf[n]),
- nxt_iobuf_size(&sb->iobuf[n]));
+ nxt_debug(task, "sendbuf: %ui, %p, %uz", n,
+ nxt_iobuf_data(&sb->iobuf[n]),
+ nxt_iobuf_size(&sb->iobuf[n]));
total += size;
last = b->mem.pos + size;
@@ -300,7 +300,7 @@ nxt_sendbuf_update(nxt_buf_t *b, size_t sent)
nxt_buf_t *
-nxt_sendbuf_completion(nxt_thread_t *thr, nxt_work_queue_t *wq, nxt_buf_t *b,
+nxt_sendbuf_completion(nxt_task_t *task, nxt_work_queue_t *wq, nxt_buf_t *b,
size_t sent)
{
size_t size;
@@ -343,8 +343,8 @@ nxt_sendbuf_completion(nxt_thread_t *thr, nxt_work_queue_t *wq, nxt_buf_t *b,
}
}
- nxt_thread_work_queue_add(thr, wq, b->completion_handler,
- b, b->parent, thr->log);
+ nxt_thread_work_queue_add(task->thread, wq, b->completion_handler, task,
+ b, b->parent);
b = b->next;
}
diff --git a/src/nxt_sendbuf.h b/src/nxt_sendbuf.h
index 338bb84f..ca314e7b 100644
--- a/src/nxt_sendbuf.h
+++ b/src/nxt_sendbuf.h
@@ -88,7 +88,8 @@ ssize_t nxt_event_conn_io_sendbuf(nxt_event_conn_t *c, nxt_buf_t *b,
size_t limit);
-nxt_uint_t nxt_sendbuf_mem_coalesce(nxt_sendbuf_coalesce_t *sb);
+nxt_uint_t nxt_sendbuf_mem_coalesce(nxt_task_t *task,
+ nxt_sendbuf_coalesce_t *sb);
size_t nxt_sendbuf_file_coalesce(nxt_sendbuf_coalesce_t *sb);
/*
@@ -101,7 +102,7 @@ ssize_t nxt_sendbuf_copy_coalesce(nxt_event_conn_t *c, nxt_buf_mem_t *bm,
nxt_buf_t *b, size_t limit);
nxt_buf_t *nxt_sendbuf_update(nxt_buf_t *b, size_t sent);
-nxt_buf_t *nxt_sendbuf_completion(nxt_thread_t *thr, nxt_work_queue_t *wq,
+nxt_buf_t *nxt_sendbuf_completion(nxt_task_t *task, nxt_work_queue_t *wq,
nxt_buf_t *b, size_t sent);
diff --git a/src/nxt_sockaddr.c b/src/nxt_sockaddr.c
index b2515ef9..f14f690d 100644
--- a/src/nxt_sockaddr.c
+++ b/src/nxt_sockaddr.c
@@ -495,7 +495,7 @@ nxt_job_sockaddr_parse(nxt_job_sockaddr_parse_t *jbs)
return;
}
- nxt_job_return(nxt_thread(), &jbs->resolve.job, handler);
+ nxt_job_return(&jbs->resolve.job.task, &jbs->resolve.job, handler);
}
diff --git a/src/nxt_socketpair.c b/src/nxt_socketpair.c
index 20336d38..4a7cbbaa 100644
--- a/src/nxt_socketpair.c
+++ b/src/nxt_socketpair.c
@@ -82,8 +82,7 @@ nxt_socketpair_send(nxt_event_fd_t *ev, nxt_fd_t fd, nxt_iobuf_t *iob,
err = (n == -1) ? nxt_socket_errno : 0;
- nxt_log_debug(ev->log, "sendmsg(%d, %FD, %ui): %z",
- ev->fd, fd, niob, n);
+ nxt_debug(ev->task, "sendmsg(%d, %FD, %ui): %z", ev->fd, fd, niob, n);
if (n > 0) {
return n;
@@ -94,18 +93,19 @@ nxt_socketpair_send(nxt_event_fd_t *ev, nxt_fd_t fd, nxt_iobuf_t *iob,
switch (err) {
case NXT_EAGAIN:
- nxt_log_debug(ev->log, "sendmsg(%d) not ready", ev->fd);
+ nxt_debug(ev->task, "sendmsg(%d) not ready", ev->fd);
ev->write_ready = 0;
+
return NXT_AGAIN;
case NXT_EINTR:
- nxt_log_debug(ev->log, "sendmsg(%d) interrupted", ev->fd);
+ nxt_debug(ev->task, "sendmsg(%d) interrupted", ev->fd);
continue;
default:
- nxt_log_error(NXT_LOG_CRIT, ev->log,
- "sendmsg(%d, %FD, %ui) failed %E",
- ev->fd, fd, niob, err);
+ nxt_log(ev->task, NXT_LOG_CRIT, "sendmsg(%d, %FD, %ui) failed %E",
+ ev->fd, fd, niob, err);
+
return NXT_ERROR;
}
}
@@ -124,8 +124,7 @@ nxt_socketpair_recv(nxt_event_fd_t *ev, nxt_fd_t *fd, nxt_iobuf_t *iob,
err = (n == -1) ? nxt_socket_errno : 0;
- nxt_log_debug(ev->log, "recvmsg(%d, %FD, %ui): %z",
- ev->fd, *fd, niob, n);
+ nxt_debug(ev->task, "recvmsg(%d, %FD, %ui): %z", ev->fd, *fd, niob, n);
if (n > 0) {
return n;
@@ -134,6 +133,7 @@ nxt_socketpair_recv(nxt_event_fd_t *ev, nxt_fd_t *fd, nxt_iobuf_t *iob,
if (n == 0) {
ev->closed = 1;
ev->read_ready = 0;
+
return n;
}
@@ -142,18 +142,19 @@ nxt_socketpair_recv(nxt_event_fd_t *ev, nxt_fd_t *fd, nxt_iobuf_t *iob,
switch (err) {
case NXT_EAGAIN:
- nxt_log_debug(ev->log, "recvmsg(%d) not ready", ev->fd);
+ nxt_debug(ev->task, "recvmsg(%d) not ready", ev->fd);
ev->read_ready = 0;
+
return NXT_AGAIN;
case NXT_EINTR:
- nxt_log_debug(ev->log, "recvmsg(%d) interrupted", ev->fd);
+ nxt_debug(ev->task, "recvmsg(%d) interrupted", ev->fd);
continue;
default:
- nxt_log_error(NXT_LOG_CRIT, ev->log,
- "recvmsg(%d, %p, %ui) failed %E",
- ev->fd, fd, niob, err);
+ nxt_log(ev->task, NXT_LOG_CRIT, "recvmsg(%d, %p, %ui) failed %E",
+ ev->fd, fd, niob, err);
+
return NXT_ERROR;
}
}
diff --git a/src/nxt_source.h b/src/nxt_source.h
index 23bebb3c..976cc8f9 100644
--- a/src/nxt_source.h
+++ b/src/nxt_source.h
@@ -23,20 +23,20 @@ typedef void (*nxt_source_handler_t)(void *source_context,
#define \
-nxt_source_filter(thr, wq, next, out) \
+nxt_source_filter(thr, wq, task, next, out) \
do { \
if (thr->engine->batch != 0) { \
nxt_thread_work_queue_add(thr, wq, nxt_source_filter_handler, \
- next, out, thr->log); \
+ task, next, out); \
\
} else { \
- (next)->filter(thr, (next)->context, out); \
+ (next)->filter(task, (next)->context, out); \
} \
\
} while (0)
-NXT_EXPORT void nxt_source_filter_handler(nxt_thread_t *thr, void *obj,
+NXT_EXPORT void nxt_source_filter_handler(nxt_task_t *task, void *obj,
void *data);
diff --git a/src/nxt_ssltls.h b/src/nxt_ssltls.h
index 7bdc1946..aa32348d 100644
--- a/src/nxt_ssltls.h
+++ b/src/nxt_ssltls.h
@@ -34,7 +34,7 @@ typedef struct {
struct nxt_ssltls_conf_s {
void *ctx;
- void (*conn_init)(nxt_thread_t *thr,
+ void (*conn_init)(nxt_task_t *task,
nxt_ssltls_conf_t *conf,
nxt_event_conn_t *c);
diff --git a/src/nxt_stream_source.c b/src/nxt_stream_source.c
index 33159ee9..9b667b99 100644
--- a/src/nxt_stream_source.c
+++ b/src/nxt_stream_source.c
@@ -7,22 +7,22 @@
#include <nxt_main.h>
-static void nxt_stream_source_connected(nxt_thread_t *thr, void *obj,
+static void nxt_stream_source_connected(nxt_task_t *task, void *obj,
void *data);
-static void nxt_stream_source_write_ready(nxt_thread_t *thr, void *obj,
+static void nxt_stream_source_write_ready(nxt_task_t *task, void *obj,
void *data);
-static void nxt_stream_source_read_ready(nxt_thread_t *thr, void *obj,
+static void nxt_stream_source_read_ready(nxt_task_t *task, void *obj,
void *data);
static nxt_buf_t *nxt_stream_source_process_buffers(nxt_stream_source_t *stream,
nxt_event_conn_t *c);
-static void nxt_stream_source_buf_completion(nxt_thread_t *thr, void *obj,
+static void nxt_stream_source_buf_completion(nxt_task_t *task, void *obj,
void *data);
-static void nxt_stream_source_read_done(nxt_thread_t *thr, void *obj,
+static void nxt_stream_source_read_done(nxt_task_t *task, void *obj,
void *data);
-static void nxt_stream_source_refused(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_stream_source_closed(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_stream_source_error(nxt_thread_t *thr, void *obj, void *data);
-static void nxt_stream_source_close(nxt_thread_t *thr,
+static void nxt_stream_source_refused(nxt_task_t *task, void *obj, void *data);
+static void nxt_stream_source_closed(nxt_task_t *task, void *obj, void *data);
+static void nxt_stream_source_error(nxt_task_t *task, void *obj, void *data);
+static void nxt_stream_source_close(nxt_task_t *task,
nxt_stream_source_t *stream);
@@ -33,7 +33,7 @@ static const nxt_event_conn_state_t nxt_stream_source_response_read_state;
void
-nxt_stream_source_connect(nxt_stream_source_t *stream)
+nxt_stream_source_connect(nxt_task_t *task, nxt_stream_source_t *stream)
{
nxt_thread_t *thr;
nxt_event_conn_t *c;
@@ -44,9 +44,9 @@ nxt_stream_source_connect(nxt_stream_source_t *stream)
us = stream->upstream;
if (nxt_slow_path(!nxt_buf_pool_obtainable(&us->buffers))) {
- nxt_thread_log_error(NXT_LOG_ERR, "%d buffers %uDK each "
- "are not enough to read upstream response",
- us->buffers.max, us->buffers.size / 1024);
+ nxt_log(task, NXT_LOG_ERR,
+ "%d buffers %uDK each are not enough to read upstream response",
+ us->buffers.max, us->buffers.size / 1024);
goto fail;
}
@@ -63,12 +63,12 @@ nxt_stream_source_connect(nxt_stream_source_t *stream)
c->remote = us->peer->sockaddr;
c->write_state = &nxt_stream_source_connect_state;
- nxt_event_conn_connect(thr, c);
+ nxt_event_conn_connect(task, c);
return;
fail:
- stream->error_handler(stream);
+ stream->error_handler(task, stream);
}
@@ -89,7 +89,7 @@ static const nxt_event_conn_state_t nxt_stream_source_connect_state
static void
-nxt_stream_source_connected(nxt_thread_t *thr, void *obj, void *data)
+nxt_stream_source_connected(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
nxt_stream_source_t *stream;
@@ -97,21 +97,22 @@ nxt_stream_source_connected(nxt_thread_t *thr, void *obj, void *data)
c = obj;
stream = data;
- nxt_log_debug(thr->log, "stream source connected fd:%d", c->socket.fd);
+ nxt_debug(task, "stream source connected fd:%d", c->socket.fd);
c->read_state = &nxt_stream_source_response_ready_state;
c->write = stream->out;
c->write_state = &nxt_stream_source_request_write_state;
- if (thr->engine->batch != 0) {
- nxt_event_conn_write(thr, c);
+ if (task->thread->engine->batch != 0) {
+ nxt_event_conn_write(task, c);
} else {
stream->read_queued = 1;
- nxt_thread_work_queue_add(thr, &thr->engine->read_work_queue,
- c->io->read, c, stream, thr->log);
+ nxt_thread_work_queue_add(task->thread,
+ &task->thread->engine->read_work_queue,
+ c->io->read, task, c, stream);
- c->io->write(thr, c, stream);
+ c->io->write(task, c, stream);
}
}
@@ -149,20 +150,20 @@ static const nxt_event_conn_state_t nxt_stream_source_response_ready_state
static void
-nxt_stream_source_write_ready(nxt_thread_t *thr, void *obj, void *data)
+nxt_stream_source_write_ready(nxt_task_t *task, void *obj, void *data)
{
nxt_event_conn_t *c;
c = obj;
- nxt_log_debug(thr->log, "stream source write ready fd:%d", c->socket.fd);
+ nxt_debug(task, "stream source write ready fd:%d", c->socket.fd);
- nxt_event_conn_read(thr, c);
+ nxt_event_conn_read(task, c);
}
static void
-nxt_stream_source_read_ready(nxt_thread_t *thr, void *obj, void *data)
+nxt_stream_source_read_ready(nxt_task_t *task, void *obj, void *data)
{
nxt_int_t ret;
nxt_buf_t *b;
@@ -174,7 +175,7 @@ nxt_stream_source_read_ready(nxt_thread_t *thr, void *obj, void *data)
stream = data;
stream->read_queued = 0;
- nxt_log_debug(thr->log, "stream source read ready fd:%d", c->socket.fd);
+ nxt_debug(task, "stream source read ready fd:%d", c->socket.fd);
if (c->read == NULL) {
@@ -190,7 +191,7 @@ nxt_stream_source_read_ready(nxt_thread_t *thr, void *obj, void *data)
/* ret == NXT_AGAIN */
- nxt_log_debug(thr->log, "stream source flush");
+ nxt_debug(task, "stream source flush");
b = nxt_buf_sync_alloc(buffers->mem_pool, NXT_BUF_SYNC_NOBUF);
@@ -198,9 +199,10 @@ nxt_stream_source_read_ready(nxt_thread_t *thr, void *obj, void *data)
goto fail;
}
- nxt_event_fd_block_read(thr->engine, &c->socket);
+ nxt_event_fd_block_read(task->thread->engine, &c->socket);
- nxt_source_filter(thr, c->write_work_queue, stream->next, b);
+ nxt_source_filter(task->thread, c->write_work_queue, task,
+ stream->next, b);
return;
}
@@ -210,12 +212,12 @@ nxt_stream_source_read_ready(nxt_thread_t *thr, void *obj, void *data)
c->read_state = &nxt_stream_source_response_read_state;
- nxt_event_conn_read(thr, c);
+ nxt_event_conn_read(task, c);
return;
fail:
- nxt_stream_source_close(thr, stream);
+ nxt_stream_source_close(task, stream);
}
@@ -236,7 +238,7 @@ static const nxt_event_conn_state_t nxt_stream_source_response_read_state
static void
-nxt_stream_source_read_done(nxt_thread_t *thr, void *obj, void *data)
+nxt_stream_source_read_done(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b;
nxt_bool_t batch;
@@ -246,33 +248,35 @@ nxt_stream_source_read_done(nxt_thread_t *thr, void *obj, void *data)
c = obj;
stream = data;
- nxt_log_debug(thr->log, "stream source read done fd:%d", c->socket.fd);
+ nxt_debug(task, "stream source read done fd:%d", c->socket.fd);
if (c->read != NULL) {
b = nxt_stream_source_process_buffers(stream, c);
if (nxt_slow_path(b == NULL)) {
- nxt_stream_source_close(thr, stream);
+ nxt_stream_source_close(task, stream);
return;
}
- batch = (thr->engine->batch != 0);
+ batch = (task->thread->engine->batch != 0);
if (batch) {
- nxt_thread_work_queue_add(thr, stream->upstream->work_queue,
+ nxt_thread_work_queue_add(task->thread,
+ stream->upstream->work_queue,
nxt_source_filter_handler,
- stream->next, b, thr->log);
+ task, stream->next, b);
}
if (!stream->read_queued) {
stream->read_queued = 1;
- nxt_thread_work_queue_add(thr, stream->upstream->work_queue,
+ nxt_thread_work_queue_add(task->thread,
+ stream->upstream->work_queue,
nxt_stream_source_read_ready,
- c, stream, thr->log);
+ task, c, stream);
}
if (!batch) {
- stream->next->filter(thr, stream->next->context, b);
+ stream->next->filter(task, stream->next->context, b);
}
}
}
@@ -335,7 +339,7 @@ nxt_stream_source_process_buffers(nxt_stream_source_t *stream,
static void
-nxt_stream_source_buf_completion(nxt_thread_t *thr, void *obj, void *data)
+nxt_stream_source_buf_completion(nxt_task_t *task, void *obj, void *data)
{
size_t size;
nxt_buf_t *b, *parent;
@@ -345,7 +349,7 @@ nxt_stream_source_buf_completion(nxt_thread_t *thr, void *obj, void *data)
parent = data;
#if 0
- nxt_log_debug(thr->log,
+ nxt_debug(thr->log,
"stream source buf completion: %p parent:%p retain:%uD",
b, parent, parent->retain);
#endif
@@ -375,11 +379,11 @@ nxt_stream_source_buf_completion(nxt_thread_t *thr, void *obj, void *data)
if (!stream->read_queued) {
stream->read_queued = 1;
- nxt_thread_work_queue_add(thr, stream->upstream->work_queue,
+ nxt_thread_work_queue_add(task->thread,
+ stream->upstream->work_queue,
nxt_stream_source_read_ready,
- stream->conn,
- stream->conn->socket.data,
- stream->conn->socket.log);
+ task, stream->conn,
+ stream->conn->socket.data);
}
}
}
@@ -389,7 +393,7 @@ nxt_stream_source_buf_completion(nxt_thread_t *thr, void *obj, void *data)
static void
-nxt_stream_source_refused(nxt_thread_t *thr, void *obj, void *data)
+nxt_stream_source_refused(nxt_task_t *task, void *obj, void *data)
{
nxt_stream_source_t *stream;
@@ -401,16 +405,16 @@ nxt_stream_source_refused(nxt_thread_t *thr, void *obj, void *data)
c = obj;
- nxt_log_debug(thr->log, "stream source refused fd:%d", c->socket.fd);
+ nxt_debug(task, "stream source refused fd:%d", c->socket.fd);
}
#endif
- nxt_stream_source_close(thr, stream);
+ nxt_stream_source_close(task, stream);
}
static void
-nxt_stream_source_closed(nxt_thread_t *thr, void *obj, void *data)
+nxt_stream_source_closed(nxt_task_t *task, void *obj, void *data)
{
nxt_buf_t *b;
nxt_event_conn_t *c;
@@ -419,24 +423,24 @@ nxt_stream_source_closed(nxt_thread_t *thr, void *obj, void *data)
c = obj;
stream = data;
- nxt_log_debug(thr->log, "stream source closed fd:%d", c->socket.fd);
+ nxt_debug(task, "stream source closed fd:%d", c->socket.fd);
- nxt_event_conn_close(thr, c);
+ nxt_event_conn_close(task, c);
b = nxt_buf_sync_alloc(stream->upstream->buffers.mem_pool,
NXT_BUF_SYNC_LAST);
if (nxt_slow_path(b == NULL)) {
- stream->error_handler(stream);
+ stream->error_handler(task, stream);
return;
}
- nxt_source_filter(thr, c->write_work_queue, stream->next, b);
+ nxt_source_filter(task->thread, c->write_work_queue, task, stream->next, b);
}
static void
-nxt_stream_source_error(nxt_thread_t *thr, void *obj, void *data)
+nxt_stream_source_error(nxt_task_t *task, void *obj, void *data)
{
nxt_stream_source_t *stream;
@@ -448,29 +452,29 @@ nxt_stream_source_error(nxt_thread_t *thr, void *obj, void *data)
ev = obj;
- nxt_log_debug(thr->log, "stream source error fd:%d", ev->fd);
+ nxt_debug(task, "stream source error fd:%d", ev->fd);
}
#endif
- nxt_stream_source_close(thr, stream);
+ nxt_stream_source_close(task, stream);
}
static void
-nxt_stream_source_close(nxt_thread_t *thr, nxt_stream_source_t *stream)
+nxt_stream_source_close(nxt_task_t *task, nxt_stream_source_t *stream)
{
- nxt_event_conn_close(thr, stream->conn);
+ nxt_event_conn_close(task, stream->conn);
- stream->error_handler(stream);
+ stream->error_handler(task, stream);
}
void
-nxt_source_filter_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_source_filter_handler(nxt_task_t *task, void *obj, void *data)
{
nxt_source_hook_t *next;
next = obj;
- next->filter(thr, next->context, data);
+ next->filter(task, next->context, data);
}
diff --git a/src/nxt_stream_source.h b/src/nxt_stream_source.h
index ae8d5b71..27a6bfc8 100644
--- a/src/nxt_stream_source.h
+++ b/src/nxt_stream_source.h
@@ -10,7 +10,8 @@
typedef struct nxt_stream_source_s nxt_stream_source_t;
-typedef void (*nxt_stream_source_handler_t)(nxt_stream_source_t *u);
+typedef void (*nxt_stream_source_handler_t)(nxt_task_t *task,
+ nxt_stream_source_t *s);
struct nxt_stream_source_s {
nxt_event_conn_t *conn;
@@ -25,7 +26,7 @@ struct nxt_stream_source_s {
};
-void nxt_stream_source_connect(nxt_stream_source_t *stream);
+void nxt_stream_source_connect(nxt_task_t *task, nxt_stream_source_t *stream);
#endif /* _NXT_STREAM_SOURCE_H_INCLUDED_ */
diff --git a/src/nxt_thread.c b/src/nxt_thread.c
index 415253c0..680412c2 100644
--- a/src/nxt_thread.c
+++ b/src/nxt_thread.c
@@ -184,8 +184,9 @@ nxt_thread_exit(nxt_thread_t *thr)
if (thr->link != NULL) {
nxt_event_engine_post(thr->link->engine, thr->link->exit,
- (void *) (uintptr_t) thr->handle, NULL,
- &nxt_main_log);
+ &thr->link->engine->task,
+ (void *) (uintptr_t) thr->handle,
+ NULL, &nxt_main_log);
nxt_free(thr->link);
thr->link = NULL;
diff --git a/src/nxt_thread_pool.c b/src/nxt_thread_pool.c
index a9708ed2..463bfad4 100644
--- a/src/nxt_thread_pool.c
+++ b/src/nxt_thread_pool.c
@@ -8,7 +8,7 @@
static nxt_int_t nxt_thread_pool_init(nxt_thread_pool_t *tp);
-static void nxt_thread_pool_exit(nxt_thread_t *thr, void *obj, void *data);
+static void nxt_thread_pool_exit(nxt_task_t *task, void *obj, void *data);
static void nxt_thread_pool_start(void *ctx);
static void nxt_thread_pool_wait(nxt_thread_pool_t *tp);
@@ -28,6 +28,8 @@ nxt_thread_pool_create(nxt_uint_t max_threads, nxt_nsec_t timeout,
tp->max_threads = max_threads;
tp->timeout = timeout;
tp->engine = engine;
+ tp->task.thread = engine->task.thread;
+ tp->task.log = engine->task.log;
tp->init = init;
tp->exit = exit;
@@ -37,7 +39,7 @@ nxt_thread_pool_create(nxt_uint_t max_threads, nxt_nsec_t timeout,
nxt_int_t
nxt_thread_pool_post(nxt_thread_pool_t *tp, nxt_work_handler_t handler,
- void *obj, void *data, nxt_log_t *log)
+ nxt_task_t *task, void *obj, void *data)
{
nxt_thread_log_debug("thread pool post");
@@ -45,7 +47,7 @@ nxt_thread_pool_post(nxt_thread_pool_t *tp, nxt_work_handler_t handler,
return NXT_ERROR;
}
- nxt_locked_work_queue_add(&tp->work_queue, handler, obj, data, log);
+ nxt_locked_work_queue_add(&tp->work_queue, handler, task, obj, data);
(void) nxt_sem_post(&tp->sem);
@@ -117,6 +119,7 @@ static void
nxt_thread_pool_start(void *ctx)
{
void *obj, *data;
+ nxt_task_t *task;
nxt_thread_t *thr;
nxt_thread_pool_t *tp;
nxt_work_handler_t handler;
@@ -129,6 +132,8 @@ nxt_thread_pool_start(void *ctx)
tp->main = thr->handle;
nxt_free(thr->link);
thr->link = NULL;
+
+ tp->task.thread = thr;
}
thr->thread_pool = tp;
@@ -142,24 +147,25 @@ nxt_thread_pool_start(void *ctx)
for ( ;; ) {
nxt_thread_pool_wait(tp);
- handler = nxt_locked_work_queue_pop(&tp->work_queue, &obj,
- &data, &thr->log);
+ handler = nxt_locked_work_queue_pop(&tp->work_queue, &task, &obj,
+ &data);
if (nxt_fast_path(handler != NULL)) {
+ task->thread = thr;
nxt_log_debug(thr->log, "locked work queue");
- handler(thr, obj, data);
+ handler(task, obj, data);
}
for ( ;; ) {
thr->log = &nxt_main_log;
- handler = nxt_thread_work_queue_pop(thr, &obj, &data, &thr->log);
+ handler = nxt_thread_work_queue_pop(thr, &task, &obj, &data);
if (handler == NULL) {
break;
}
- handler(thr, obj, data);
+ handler(task, obj, data);
}
thr->log = &nxt_main_log;
@@ -236,11 +242,11 @@ nxt_thread_pool_destroy(nxt_thread_pool_t *tp)
{
nxt_thread_t *thr;
- if (!tp->ready) {
- thr = nxt_thread();
+ thr = nxt_thread();
+ if (!tp->ready) {
nxt_thread_work_queue_add(thr, &thr->work_queue.main, tp->exit,
- tp, NULL, &nxt_main_log);
+ &tp->task, tp, NULL);
return;
}
@@ -248,7 +254,7 @@ nxt_thread_pool_destroy(nxt_thread_pool_t *tp)
/* Disable new threads creation and mark a pool as being destroyed. */
tp->max_threads = 0;
- nxt_thread_pool_post(tp, nxt_thread_pool_exit, tp, NULL, &nxt_main_log);
+ nxt_thread_pool_post(tp, nxt_thread_pool_exit, &tp->task, tp, NULL);
}
}
@@ -265,15 +271,17 @@ nxt_thread_pool_destroy(nxt_thread_pool_t *tp)
*/
static void
-nxt_thread_pool_exit(nxt_thread_t *thr, void *obj, void *data)
+nxt_thread_pool_exit(nxt_task_t *task, void *obj, void *data)
{
+ nxt_thread_t *thread;
nxt_thread_pool_t *tp;
nxt_atomic_uint_t threads;
nxt_thread_handle_t handle;
tp = obj;
+ thread = task->thread;
- nxt_log_debug(thr->log, "thread pool exit");
+ nxt_debug(task, "thread pool exit");
if (data != NULL) {
handle = (nxt_thread_handle_t) (uintptr_t) data;
@@ -282,17 +290,18 @@ nxt_thread_pool_exit(nxt_thread_t *thr, void *obj, void *data)
threads = nxt_atomic_fetch_add(&tp->threads, -1);
- nxt_log_debug(thr->log, "thread pool threads: %A", threads);
+ nxt_debug(task, "thread pool threads: %A", threads);
if (threads > 1) {
- nxt_thread_pool_post(tp, nxt_thread_pool_exit, tp,
- (void *) (uintptr_t) thr->handle, &nxt_main_log);
+ nxt_thread_pool_post(tp, nxt_thread_pool_exit, &tp->task, tp,
+ (void *) (uintptr_t) thread->handle);
} else {
- nxt_main_log_debug("thread pool destroy");
+ nxt_debug(task, "thread pool destroy");
- nxt_event_engine_post(tp->engine, tp->exit, tp,
- (void *) (uintptr_t) thr->handle, &nxt_main_log);
+ nxt_event_engine_post(tp->engine, tp->exit, &tp->task, tp,
+ (void *) (uintptr_t) thread->handle,
+ &nxt_main_log);
nxt_sem_destroy(&tp->sem);
@@ -301,8 +310,9 @@ nxt_thread_pool_exit(nxt_thread_t *thr, void *obj, void *data)
nxt_free(tp);
}
- nxt_thread_work_queue_destroy(thr);
+ nxt_thread_work_queue_destroy(thread);
+
+ nxt_thread_exit(thread);
- nxt_thread_exit(thr);
nxt_unreachable();
}
diff --git a/src/nxt_thread_pool.h b/src/nxt_thread_pool.h
index eb359260..75899a06 100644
--- a/src/nxt_thread_pool.h
+++ b/src/nxt_thread_pool.h
@@ -20,6 +20,8 @@ struct nxt_thread_pool_s {
nxt_sem_t sem;
nxt_nsec_t timeout;
+ nxt_task_t task;
+
nxt_locked_work_queue_t work_queue;
nxt_thread_handle_t main;
@@ -35,7 +37,7 @@ NXT_EXPORT nxt_thread_pool_t *nxt_thread_pool_create(nxt_uint_t max_threads,
nxt_event_engine_t *engine, nxt_work_handler_t exit);
NXT_EXPORT void nxt_thread_pool_destroy(nxt_thread_pool_t *tp);
NXT_EXPORT nxt_int_t nxt_thread_pool_post(nxt_thread_pool_t *tp,
- nxt_work_handler_t handler, void *obj, void *data, nxt_log_t *log);
+ nxt_work_handler_t handler, nxt_task_t *task, void *obj, void *data);
#endif /* _NXT_UNIX_THREAD_POOL_H_INCLUDED_ */
diff --git a/src/nxt_unix.h b/src/nxt_unix.h
index 41b9ae3c..6f2e280b 100644
--- a/src/nxt_unix.h
+++ b/src/nxt_unix.h
@@ -234,7 +234,7 @@
#if (NXT_TEST_BUILD)
-#include <unix/nxt_test_build.h>
+#include <nxt_test_build.h>
#endif
diff --git a/src/nxt_work_queue.c b/src/nxt_work_queue.c
index 914d6125..ffb9317f 100644
--- a/src/nxt_work_queue.c
+++ b/src/nxt_work_queue.c
@@ -30,7 +30,7 @@ static void nxt_work_queue_allocate(nxt_work_queue_cache_t *cache,
static void nxt_work_queue_sleep(nxt_thread_spinlock_t *lock);
static nxt_work_queue_t *nxt_thread_current_work_queue(nxt_thread_t *thr);
static nxt_work_handler_t nxt_locked_work_queue_pop_work(
- nxt_locked_work_queue_t *lwq, void **obj, void **data, nxt_log_t **log);
+ nxt_locked_work_queue_t *lwq, nxt_task_t **task, void **obj, void **data);
/* It should be adjusted with the "work_queue_bucket_items" directive. */
@@ -130,7 +130,7 @@ nxt_work_queue_sleep(nxt_thread_spinlock_t *lock)
void
nxt_thread_work_queue_add(nxt_thread_t *thr, nxt_work_queue_t *wq,
- nxt_work_handler_t handler, void *obj, void *data, nxt_log_t *log)
+ nxt_work_handler_t handler, nxt_task_t *task, void *obj, void *data)
{
nxt_work_t *work;
@@ -144,9 +144,9 @@ nxt_thread_work_queue_add(nxt_thread_t *thr, nxt_work_queue_t *wq,
work->next = NULL;
work->handler = handler;
+ work->task = task;
work->obj = obj;
work->data = data;
- work->log = log;
if (wq->tail != NULL) {
wq->tail->next = work;
@@ -169,7 +169,7 @@ nxt_thread_work_queue_add(nxt_thread_t *thr, nxt_work_queue_t *wq,
void
nxt_thread_work_queue_push(nxt_thread_t *thr, nxt_work_queue_t *wq,
- nxt_work_handler_t handler, void *obj, void *data, nxt_log_t *log)
+ nxt_work_handler_t handler, nxt_task_t *task, void *obj, void *data)
{
nxt_work_t *work;
@@ -185,7 +185,6 @@ nxt_thread_work_queue_push(nxt_thread_t *thr, nxt_work_queue_t *wq,
work->handler = handler;
work->obj = obj;
work->data = data;
- work->log = log;
wq->head = work;
@@ -223,8 +222,8 @@ nxt_work_queue_attach(nxt_thread_t *thr, nxt_work_queue_t *wq)
/* Pop a work from a thread work queue head. */
nxt_work_handler_t
-nxt_thread_work_queue_pop(nxt_thread_t *thr, void **obj, void **data,
- nxt_log_t **log)
+nxt_thread_work_queue_pop(nxt_thread_t *thr, nxt_task_t **task, void **obj,
+ void **data)
{
nxt_work_t *work;
nxt_work_queue_t *wq;
@@ -242,6 +241,7 @@ nxt_thread_work_queue_pop(nxt_thread_t *thr, void **obj, void **data,
wq->tail = NULL;
}
+ *task = work->task;
*obj = work->obj;
nxt_prefetch(*obj);
*data = work->data;
@@ -250,8 +250,6 @@ nxt_thread_work_queue_pop(nxt_thread_t *thr, void **obj, void **data,
work->next = thr->work_queue.cache.next;
thr->work_queue.cache.next = work;
- *log = work->log;
-
#if (NXT_DEBUG)
if (work->handler == NULL) {
@@ -335,7 +333,7 @@ nxt_thread_work_queue_drop(nxt_thread_t *thr, void *data)
void
nxt_thread_last_work_queue_add(nxt_thread_t *thr, nxt_work_handler_t handler,
- void *obj, void *data, nxt_log_t *log)
+ void *obj, void *data)
{
nxt_work_t *work;
@@ -349,7 +347,6 @@ nxt_thread_last_work_queue_add(nxt_thread_t *thr, nxt_work_handler_t handler,
work->handler = handler;
work->obj = obj;
work->data = data;
- work->log = log;
if (thr->work_queue.last.tail != NULL) {
thr->work_queue.last.tail->next = work;
@@ -371,8 +368,8 @@ nxt_thread_last_work_queue_add(nxt_thread_t *thr, nxt_work_handler_t handler,
/* Pop a work from the thread last work queue's head. */
nxt_work_handler_t
-nxt_thread_last_work_queue_pop(nxt_thread_t *thr, void **obj, void **data,
- nxt_log_t **log)
+nxt_thread_last_work_queue_pop(nxt_thread_t *thr, nxt_task_t **task, void **obj,
+ void **data)
{
nxt_work_t *work;
@@ -387,6 +384,7 @@ nxt_thread_last_work_queue_pop(nxt_thread_t *thr, void **obj, void **data,
thr->work_queue.last.tail = NULL;
}
+ *task = work->task;
*obj = work->obj;
nxt_prefetch(*obj);
*data = work->data;
@@ -395,8 +393,6 @@ nxt_thread_last_work_queue_pop(nxt_thread_t *thr, void **obj, void **data,
work->next = thr->work_queue.cache.next;
thr->work_queue.cache.next = work;
- *log = work->log;
-
#if (NXT_DEBUG)
if (work->handler == NULL) {
@@ -491,7 +487,7 @@ nxt_locked_work_queue_destroy(nxt_locked_work_queue_t *lwq)
void
nxt_locked_work_queue_add(nxt_locked_work_queue_t *lwq,
- nxt_work_handler_t handler, void *obj, void *data, nxt_log_t *log)
+ nxt_work_handler_t handler, nxt_task_t *task, void *obj, void *data)
{
nxt_work_t *work;
@@ -505,9 +501,9 @@ nxt_locked_work_queue_add(nxt_locked_work_queue_t *lwq,
work->next = NULL;
work->handler = handler;
+ work->task = task;
work->obj = obj;
work->data = data;
- work->log = log;
if (lwq->tail != NULL) {
lwq->tail->next = work;
@@ -531,14 +527,14 @@ nxt_locked_work_queue_add(nxt_locked_work_queue_t *lwq,
/* Pop a work from a locked work queue head. */
nxt_work_handler_t
-nxt_locked_work_queue_pop(nxt_locked_work_queue_t *lwq, void **obj,
- void **data, nxt_log_t **log)
+nxt_locked_work_queue_pop(nxt_locked_work_queue_t *lwq, nxt_task_t **task,
+ void **obj, void **data)
{
nxt_work_handler_t handler;
nxt_thread_spin_lock(&lwq->lock);
- handler = nxt_locked_work_queue_pop_work(lwq, obj, data, log);
+ handler = nxt_locked_work_queue_pop_work(lwq, task, obj, data);
nxt_thread_spin_unlock(&lwq->lock);
@@ -547,8 +543,8 @@ nxt_locked_work_queue_pop(nxt_locked_work_queue_t *lwq, void **obj,
static nxt_work_handler_t
-nxt_locked_work_queue_pop_work(nxt_locked_work_queue_t *lwq, void **obj,
- void **data, nxt_log_t **log)
+nxt_locked_work_queue_pop_work(nxt_locked_work_queue_t *lwq, nxt_task_t **task,
+ void **obj, void **data)
{
nxt_work_t *work;
@@ -558,6 +554,7 @@ nxt_locked_work_queue_pop_work(nxt_locked_work_queue_t *lwq, void **obj,
return NULL;
}
+ *task = work->task;
*obj = work->obj;
nxt_prefetch(*obj);
*data = work->data;
@@ -572,8 +569,6 @@ nxt_locked_work_queue_pop_work(nxt_locked_work_queue_t *lwq, void **obj,
work->next = lwq->cache.next;
lwq->cache.next = work;
- *log = work->log;
-
return work->handler;
}
@@ -585,7 +580,7 @@ nxt_locked_work_queue_move(nxt_thread_t *thr, nxt_locked_work_queue_t *lwq,
nxt_work_queue_t *wq)
{
void *obj, *data;
- nxt_log_t *log;
+ nxt_task_t *task;
nxt_work_handler_t handler;
/* Locked work queue head can be tested without a lock. */
@@ -597,13 +592,15 @@ nxt_locked_work_queue_move(nxt_thread_t *thr, nxt_locked_work_queue_t *lwq,
nxt_thread_spin_lock(&lwq->lock);
for ( ;; ) {
- handler = nxt_locked_work_queue_pop_work(lwq, &obj, &data, &log);
+ handler = nxt_locked_work_queue_pop_work(lwq, &task, &obj, &data);
if (handler == NULL) {
break;
}
- nxt_thread_work_queue_add(thr, wq, handler, obj, data, log);
+ task->thread = thr;
+
+ nxt_thread_work_queue_add(thr, wq, handler, task, obj, data);
}
nxt_thread_spin_unlock(&lwq->lock);
diff --git a/src/nxt_work_queue.h b/src/nxt_work_queue.h
index 2b168b00..b37fe1a3 100644
--- a/src/nxt_work_queue.h
+++ b/src/nxt_work_queue.h
@@ -8,6 +8,22 @@
#define _NXT_WORK_QUEUE_H_INCLUDED_
+typedef struct nxt_work_s nxt_work_t;
+
+typedef struct {
+ nxt_thread_t *thread;
+ nxt_log_t *log;
+ uint32_t ident;
+ nxt_work_t *next_work;
+
+ /* TODO: exception_handler, prev/next task, subtasks. */
+} nxt_task_t;
+
+
+#define nxt_task_next_ident() \
+ ((uint32_t) nxt_atomic_fetch_add(&nxt_task_ident, 1) & 0x3fffffff)
+
+
/*
* A work handler with just the obj and data arguments instead
* of pointer to a possibly large a work struct allows to call
@@ -16,17 +32,15 @@
* source filters, so the data argument has been introduced and
* is used where appropriate.
*/
-typedef void (*nxt_work_handler_t)(nxt_thread_t *thr, void *obj, void *data);
-
-typedef struct nxt_work_s nxt_work_t;
+typedef void (*nxt_work_handler_t)(nxt_task_t *task, void *obj, void *data);
struct nxt_work_s {
nxt_work_t *next;
nxt_work_handler_t handler;
+ nxt_task_t *task;
void *obj;
void *data;
- nxt_log_t *log;
};
@@ -79,24 +93,24 @@ NXT_EXPORT void nxt_thread_work_queue_create(nxt_thread_t *thr,
size_t chunk_size);
NXT_EXPORT void nxt_thread_work_queue_destroy(nxt_thread_t *thr);
NXT_EXPORT void nxt_thread_work_queue_add(nxt_thread_t *thr,
- nxt_work_queue_t *wq,
- nxt_work_handler_t handler, void *obj, void *data, nxt_log_t *log);
+ nxt_work_queue_t *wq, nxt_work_handler_t handler, nxt_task_t *task,
+ void *obj, void *data);
NXT_EXPORT void nxt_thread_work_queue_push(nxt_thread_t *thr,
- nxt_work_queue_t *wq, nxt_work_handler_t handler, void *obj, void *data,
- nxt_log_t *log);
+ nxt_work_queue_t *wq, nxt_work_handler_t handler, nxt_task_t *task,
+ void *obj, void *data);
NXT_EXPORT void nxt_work_queue_attach(nxt_thread_t *thr, nxt_work_queue_t *wq);
NXT_EXPORT nxt_work_handler_t nxt_thread_work_queue_pop(nxt_thread_t *thr,
- void **obj, void **data, nxt_log_t **log);
+ nxt_task_t **task, void **obj, void **data);
NXT_EXPORT void nxt_thread_work_queue_drop(nxt_thread_t *thr, void *data);
#define \
-nxt_thread_current_work_queue_add(thr, handler, obj, data, log) \
+nxt_thread_current_work_queue_add(thr, handler, task, obj, data) \
do { \
nxt_thread_t *_thr = thr; \
\
nxt_thread_work_queue_add(_thr, _thr->work_queue.head, \
- handler, obj, data, log); \
+ handler, task, obj, data); \
} while (0)
@@ -118,18 +132,18 @@ nxt_work_queue_name(_wq, _name)
NXT_EXPORT void nxt_thread_last_work_queue_add(nxt_thread_t *thr,
- nxt_work_handler_t handler, void *obj, void *data, nxt_log_t *log);
+ nxt_work_handler_t handler, void *obj, void *data);
NXT_EXPORT nxt_work_handler_t nxt_thread_last_work_queue_pop(nxt_thread_t *thr,
- void **obj, void **data, nxt_log_t **log);
+ nxt_task_t **task, void **obj, void **data);
NXT_EXPORT void nxt_locked_work_queue_create(nxt_locked_work_queue_t *lwq,
size_t chunk_size);
NXT_EXPORT void nxt_locked_work_queue_destroy(nxt_locked_work_queue_t *lwq);
NXT_EXPORT void nxt_locked_work_queue_add(nxt_locked_work_queue_t *lwq,
- nxt_work_handler_t handler, void *obj, void *data, nxt_log_t *log);
+ nxt_work_handler_t handler, nxt_task_t *task, void *obj, void *data);
NXT_EXPORT nxt_work_handler_t nxt_locked_work_queue_pop(
- nxt_locked_work_queue_t *lwq, void **obj, void **data, nxt_log_t **log);
+ nxt_locked_work_queue_t *lwq, nxt_task_t **task, void **obj, void **data);
NXT_EXPORT void nxt_locked_work_queue_move(nxt_thread_t *thr,
nxt_locked_work_queue_t *lwq, nxt_work_queue_t *wq);
diff --git a/src/nxt_worker_process.c b/src/nxt_worker_process.c
index 6f64b8f9..9a5173f0 100644
--- a/src/nxt_worker_process.c
+++ b/src/nxt_worker_process.c
@@ -10,14 +10,14 @@
#include <nxt_master_process.h>
-static void nxt_worker_process_quit(nxt_thread_t *thr);
-static void nxt_worker_process_quit_handler(nxt_thread_t *thr,
+static void nxt_worker_process_quit(nxt_task_t *task);
+static void nxt_worker_process_quit_handler(nxt_task_t *task,
nxt_chan_recv_msg_t *msg);
-static void nxt_worker_process_signal_handler(nxt_thread_t *thr, void *obj,
+static void nxt_worker_process_signal_handler(nxt_task_t *task, void *obj,
void *data);
-static void nxt_worker_process_sigterm_handler(nxt_thread_t *thr, void *obj,
+static void nxt_worker_process_sigterm_handler(nxt_task_t *task, void *obj,
void *data);
-static void nxt_worker_process_sigquit_handler(nxt_thread_t *thr, void *obj,
+static void nxt_worker_process_sigquit_handler(nxt_task_t *task, void *obj,
void *data);
@@ -82,7 +82,7 @@ nxt_worker_process_start(void *data)
goto fail;
}
- if (nxt_event_engine_change(thr, event_set, cycle->batch) != NXT_OK) {
+ if (nxt_event_engine_change(thr, &nxt_main_task, event_set, cycle->batch) != NXT_OK) {
goto fail;
}
@@ -96,7 +96,7 @@ nxt_worker_process_start(void *data)
/* A master process chan. */
nxt_chan_read_close(proc[0].chan);
- nxt_chan_write_enable(thr, proc[0].chan);
+ nxt_chan_write_enable(&nxt_main_task, proc[0].chan);
/* A worker process chan. */
nxt_process_chan_create(thr, &proc[cycle->current_process],
@@ -127,7 +127,7 @@ fail:
static void
-nxt_worker_process_quit(nxt_thread_t *thr)
+nxt_worker_process_quit(nxt_task_t *task)
{
nxt_uint_t n;
nxt_cycle_t *cycle;
@@ -138,9 +138,9 @@ nxt_worker_process_quit(nxt_thread_t *thr)
cycle = nxt_thread_cycle();
- nxt_log_debug(thr->log, "close listen connections");
+ nxt_debug(task, "close listen connections");
- listen = &thr->engine->listen_connections;
+ listen = &task->thread->engine->listen_connections;
for (link = nxt_queue_first(listen);
link != nxt_queue_tail(listen);
@@ -150,7 +150,7 @@ nxt_worker_process_quit(nxt_thread_t *thr)
cls = nxt_queue_link_data(link, nxt_event_conn_listen_t, link);
nxt_queue_remove(link);
- nxt_event_fd_close(thr->engine, &cls->socket);
+ nxt_event_fd_close(task->thread->engine, &cls->socket);
}
if (cycle->listen_sockets != NULL) {
@@ -169,45 +169,44 @@ nxt_worker_process_quit(nxt_thread_t *thr)
cycle->listen_sockets->nelts = 0;
}
- nxt_cycle_quit(thr, cycle);
+ nxt_cycle_quit(task, cycle);
}
static void
-nxt_worker_process_signal_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_worker_process_signal_handler(nxt_task_t *task, void *obj, void *data)
{
- nxt_log_error(NXT_LOG_INFO, thr->log,
- "signal signo:%d (%s) recevied, ignored",
- (int) (uintptr_t) obj, data);
+ nxt_trace(task, "signal signo:%d (%s) recevied, ignored",
+ (int) (uintptr_t) obj, data);
}
static void
-nxt_worker_process_quit_handler(nxt_thread_t *thr, nxt_chan_recv_msg_t *msg)
+nxt_worker_process_quit_handler(nxt_task_t *task, nxt_chan_recv_msg_t *msg)
{
- nxt_worker_process_quit(thr);
+ nxt_worker_process_quit(task);
}
static void
-nxt_worker_process_sigterm_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_worker_process_sigterm_handler(nxt_task_t *task, void *obj, void *data)
{
- nxt_log_debug(thr->log, "sigterm handler signo:%d (%s)",
- (int) (uintptr_t) obj, data);
+ nxt_debug(task, "sigterm handler signo:%d (%s)",
+ (int) (uintptr_t) obj, data);
/* A fast exit. */
- nxt_cycle_quit(thr, NULL);
+ nxt_cycle_quit(task, NULL);
}
static void
-nxt_worker_process_sigquit_handler(nxt_thread_t *thr, void *obj, void *data)
+nxt_worker_process_sigquit_handler(nxt_task_t *task, void *obj, void *data)
{
- nxt_log_debug(thr->log, "sigquit handler signo:%d (%s)",
- (int) (uintptr_t) obj, data);
+ nxt_debug(task, "sigquit handler signo:%d (%s)",
+ (int) (uintptr_t) obj, data);
/* A graceful exit. */
- nxt_worker_process_quit(thr);
+ nxt_worker_process_quit(task);
}