summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_runtime.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2017-10-04 15:02:11 +0300
committerMax Romanov <max.romanov@nginx.com>2017-10-04 15:02:11 +0300
commite44401a0bb72aa66bec0322fa05e8c86fefc9074 (patch)
treef5a7013e7d811f13515ed7bfc9dc96ff7c6729d6 /src/nxt_runtime.c
parentf869bf1b020ed41d5a64b106ba48ec45412b912c (diff)
downloadunit-e44401a0bb72aa66bec0322fa05e8c86fefc9074.tar.gz
unit-e44401a0bb72aa66bec0322fa05e8c86fefc9074.tar.bz2
Introducing process use counter.
This helps to decouple process removal from port memory pool cleanups.
Diffstat (limited to 'src/nxt_runtime.c')
-rw-r--r--src/nxt_runtime.c30
1 files changed, 14 insertions, 16 deletions
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;
}
}