diff options
author | Max Romanov <max.romanov@nginx.com> | 2017-10-04 14:57:56 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2017-10-04 14:57:56 +0300 |
commit | ba311997866a4c2ef6ceeaac846832a85bd86f17 (patch) | |
tree | 74c268496a856065eec13b57db2a5158da2b6cd1 | |
parent | 4ae76249edb97775be8a0c749ad9ee79e3e85393 (diff) | |
download | unit-ba311997866a4c2ef6ceeaac846832a85bd86f17.tar.gz unit-ba311997866a4c2ef6ceeaac846832a85bd86f17.tar.bz2 |
Removing mem_pool from port_hash interface.
Memory pool is not used by port_hash and it was a mistake to pass it into
'add' and 'remove' functions. port_hash enrties are allocated from heap.
-rw-r--r-- | src/nxt_port_hash.c | 38 | ||||
-rw-r--r-- | src/nxt_port_hash.h | 6 | ||||
-rw-r--r-- | src/nxt_process.c | 15 | ||||
-rw-r--r-- | src/nxt_process.h | 1 | ||||
-rw-r--r-- | src/nxt_runtime.c | 15 |
5 files changed, 30 insertions, 45 deletions
diff --git a/src/nxt_port_hash.c b/src/nxt_port_hash.c index 93e46cd3..c23bcbc6 100644 --- a/src/nxt_port_hash.c +++ b/src/nxt_port_hash.c @@ -52,9 +52,19 @@ nxt_port_hash_first(nxt_lvlhsh_t *port_hash, nxt_lvlhsh_each_t *lhe) } +nxt_inline void +nxt_port_hash_lhq(nxt_lvlhsh_query_t *lhq, nxt_pid_port_id_t *pid_port) +{ + lhq->key_hash = nxt_murmur_hash2(pid_port, sizeof(nxt_pid_port_id_t)); + lhq->key.length = sizeof(nxt_pid_port_id_t); + lhq->key.start = (u_char *) pid_port; + lhq->proto = &lvlhsh_ports_proto; + lhq->pool = NULL; +} + + void -nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_mp_t *mem_pool, - nxt_port_t *port) +nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_port_t *port) { nxt_pid_port_id_t pid_port; nxt_lvlhsh_query_t lhq; @@ -62,13 +72,9 @@ nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_mp_t *mem_pool, pid_port.pid = port->pid; pid_port.port_id = port->id; - lhq.key_hash = nxt_murmur_hash2(&pid_port, sizeof(pid_port)); - lhq.key.length = sizeof(pid_port); - lhq.key.start = (u_char *) &pid_port; - lhq.proto = &lvlhsh_ports_proto; + nxt_port_hash_lhq(&lhq, &pid_port); lhq.replace = 0; lhq.value = port; - lhq.pool = mem_pool; switch (nxt_lvlhsh_insert(port_hash, &lhq)) { @@ -84,8 +90,7 @@ nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_mp_t *mem_pool, void -nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_mp_t *mem_pool, - nxt_port_t *port) +nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_port_t *port) { nxt_pid_port_id_t pid_port; nxt_lvlhsh_query_t lhq; @@ -93,13 +98,7 @@ nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_mp_t *mem_pool, pid_port.pid = port->pid; pid_port.port_id = port->id; - lhq.key_hash = nxt_murmur_hash2(&pid_port, sizeof(pid_port)); - lhq.key.length = sizeof(pid_port); - lhq.key.start = (u_char *) &pid_port; - lhq.proto = &lvlhsh_ports_proto; - lhq.replace = 0; - lhq.value = port; - lhq.pool = mem_pool; + nxt_port_hash_lhq(&lhq, &pid_port); switch (nxt_lvlhsh_delete(port_hash, &lhq)) { @@ -122,12 +121,7 @@ nxt_port_hash_find(nxt_lvlhsh_t *port_hash, nxt_pid_t pid, pid_port.pid = pid; pid_port.port_id = port_id; - lhq.key_hash = nxt_murmur_hash2(&pid_port, sizeof(pid_port)); - lhq.key.length = sizeof(pid_port); - lhq.key.start = (u_char *) &pid_port; - lhq.proto = &lvlhsh_ports_proto; - - /* TODO lock ports */ + nxt_port_hash_lhq(&lhq, &pid_port); if (nxt_lvlhsh_find(port_hash, &lhq) == NXT_OK) { nxt_thread_log_debug("process port (%PI, %d) found", pid, port_id); diff --git a/src/nxt_port_hash.h b/src/nxt_port_hash.h index 57f9ba08..68389f30 100644 --- a/src/nxt_port_hash.h +++ b/src/nxt_port_hash.h @@ -11,11 +11,9 @@ #include <nxt_main.h> -void nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_mp_t *mem_pool, - nxt_port_t *port); +void nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_port_t *port); -void nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_mp_t *mem_pool, - nxt_port_t *port); +void nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_port_t *port); nxt_port_t *nxt_port_hash_find(nxt_lvlhsh_t *port_hash, nxt_pid_t pid, nxt_port_id_t port_id); diff --git a/src/nxt_process.c b/src/nxt_process.c index e6653bd7..95e701f8 100644 --- a/src/nxt_process.c +++ b/src/nxt_process.c @@ -619,13 +619,7 @@ nxt_process_connected_port_add(nxt_process_t *process, nxt_port_t *port) { nxt_thread_mutex_lock(&process->cp_mutex); - if (process->cp_mem_pool == NULL) { - process->cp_mem_pool = nxt_mp_create(1024, 128, 256, 32); - } - - nxt_mp_thread_adopt(process->cp_mem_pool); - - nxt_port_hash_add(&process->connected_ports, process->cp_mem_pool, port); + nxt_port_hash_add(&process->connected_ports, port); nxt_thread_mutex_unlock(&process->cp_mutex); } @@ -635,12 +629,7 @@ nxt_process_connected_port_remove(nxt_process_t *process, nxt_port_t *port) { nxt_thread_mutex_lock(&process->cp_mutex); - if (process->cp_mem_pool != NULL) { - nxt_mp_thread_adopt(process->cp_mem_pool); - - nxt_port_hash_remove(&process->connected_ports, process->cp_mem_pool, - port); - } + nxt_port_hash_remove(&process->connected_ports, port); nxt_thread_mutex_unlock(&process->cp_mutex); } diff --git a/src/nxt_process.h b/src/nxt_process.h index 63302701..c3ffc702 100644 --- a/src/nxt_process.h +++ b/src/nxt_process.h @@ -58,7 +58,6 @@ typedef struct { nxt_array_t *outgoing; /* of nxt_port_mmap_t */ nxt_thread_mutex_t cp_mutex; - nxt_mp_t *cp_mem_pool; nxt_lvlhsh_t connected_ports; /* of nxt_port_t */ } nxt_process_t; diff --git a/src/nxt_runtime.c b/src/nxt_runtime.c index 886bd1ca..bfe62045 100644 --- a/src/nxt_runtime.c +++ b/src/nxt_runtime.c @@ -1586,16 +1586,21 @@ nxt_runtime_process_new(nxt_runtime_t *rt) static void 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->registered == 0); nxt_port_mmaps_destroy(process->incoming, 1); nxt_port_mmaps_destroy(process->outgoing, 1); - if (process->cp_mem_pool != NULL) { - nxt_mp_thread_adopt(process->cp_mem_pool); + port = nxt_port_hash_first(&process->connected_ports, &lhe); + + while(port != NULL) { + nxt_port_hash_remove(&process->connected_ports, port); - nxt_mp_destroy(process->cp_mem_pool); + port = nxt_port_hash_first(&process->connected_ports, &lhe); } nxt_thread_mutex_destroy(&process->incoming_mutex); @@ -1847,7 +1852,7 @@ nxt_runtime_port_first(nxt_runtime_t *rt, nxt_lvlhsh_each_t *lhe) void nxt_runtime_port_add(nxt_runtime_t *rt, nxt_port_t *port) { - nxt_port_hash_add(&rt->ports, rt->mem_pool, port); + nxt_port_hash_add(&rt->ports, port); rt->port_by_type[port->type] = port; } @@ -1856,7 +1861,7 @@ nxt_runtime_port_add(nxt_runtime_t *rt, nxt_port_t *port) void nxt_runtime_port_remove(nxt_runtime_t *rt, nxt_port_t *port) { - nxt_port_hash_remove(&rt->ports, rt->mem_pool, port); + nxt_port_hash_remove(&rt->ports, port); if (rt->port_by_type[port->type] == port) { rt->port_by_type[port->type] = NULL; |