From e44401a0bb72aa66bec0322fa05e8c86fefc9074 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Wed, 4 Oct 2017 15:02:11 +0300 Subject: Introducing process use counter. This helps to decouple process removal from port memory pool cleanups. --- src/nxt_runtime.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/nxt_runtime.c') diff --git a/src/nxt_runtime.c b/src/nxt_runtime.c index be88fc30..b1b80865 100644 --- a/src/nxt_runtime.c +++ b/src/nxt_runtime.c @@ -553,7 +553,7 @@ nxt_runtime_exit(nxt_task_t *task, void *obj, void *data) nxt_runtime_process_each(rt, process) { - nxt_runtime_process_remove(task, process); + nxt_process_close_ports(task, process); } nxt_runtime_process_loop; @@ -1580,6 +1580,8 @@ nxt_runtime_process_new(nxt_runtime_t *rt) nxt_thread_mutex_create(&process->outgoing_mutex); nxt_thread_mutex_create(&process->cp_mutex); + process->use_count = 1; + return process; } @@ -1590,7 +1592,7 @@ nxt_runtime_process_destroy(nxt_runtime_t *rt, nxt_process_t *process) nxt_port_t *port; nxt_lvlhsh_each_t lhe; - nxt_assert(process->port_cleanups == 0); + nxt_assert(process->use_count == 0); nxt_assert(process->registered == 0); nxt_port_mmaps_destroy(process->incoming, 1); @@ -1685,7 +1687,11 @@ nxt_runtime_process_get(nxt_runtime_t *rt, nxt_pid_t pid) nxt_thread_log_debug("process %PI found", pid); nxt_thread_mutex_unlock(&rt->processes_mutex); - return lhq.value; + + process = lhq.value; + process->use_count++; + + return process; } process = nxt_runtime_process_new(rt); @@ -1812,28 +1818,20 @@ nxt_runtime_process_remove_pid(nxt_runtime_t *rt, nxt_pid_t pid) void -nxt_runtime_process_remove(nxt_task_t *task, nxt_process_t *process) +nxt_process_use(nxt_task_t *task, nxt_process_t *process, int i) { - nxt_port_t *port; nxt_runtime_t *rt; - rt = task->thread->runtime; + process->use_count += i; + + if (process->use_count == 0) { + rt = task->thread->runtime; - if (process->port_cleanups == 0) { if (process->registered == 1) { nxt_runtime_process_remove_pid(rt, process->pid); } nxt_runtime_process_destroy(rt, process); - - } else { - nxt_process_port_each(process, port) { - - nxt_port_close(task, port); - - nxt_runtime_port_remove(task, port); - - } nxt_process_port_loop; } } -- cgit