diff options
author | Max Romanov <max.romanov@nginx.com> | 2020-05-28 12:41:00 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2020-05-28 12:41:00 +0300 |
commit | aacf11152c314efb1895b6d44ba72dc9f1801c7d (patch) | |
tree | 9bfa681223c46bb75c1ed0be0d0339812e487a2f /src/nxt_port_rpc.c | |
parent | de368f033dd2d22312269010f20f7f6388ecd95f (diff) | |
download | unit-aacf11152c314efb1895b6d44ba72dc9f1801c7d.tar.gz unit-aacf11152c314efb1895b6d44ba72dc9f1801c7d.tar.bz2 |
Moving nxt_stream_ident to shared memory.
This aims to avoid stream id clashes after router restart.
Diffstat (limited to 'src/nxt_port_rpc.c')
-rw-r--r-- | src/nxt_port_rpc.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/nxt_port_rpc.c b/src/nxt_port_rpc.c index 77e8af45..37f2d902 100644 --- a/src/nxt_port_rpc.c +++ b/src/nxt_port_rpc.c @@ -8,7 +8,7 @@ #include <nxt_port_rpc.h> -static nxt_atomic_t nxt_stream_ident = 1; +static volatile uint32_t *nxt_stream_ident; typedef struct nxt_port_rpc_reg_s nxt_port_rpc_reg_t; @@ -30,6 +30,29 @@ nxt_port_rpc_remove_from_peers(nxt_task_t *task, nxt_port_t *port, nxt_port_rpc_reg_t *reg); +nxt_int_t +nxt_port_rpc_init(void) +{ + void *p; + + if (nxt_stream_ident != NULL) { + return NXT_OK; + } + + p = nxt_mem_mmap(NULL, sizeof(*nxt_stream_ident), PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0); + + if (nxt_slow_path(p == MAP_FAILED)) { + return NXT_ERROR; + } + + nxt_stream_ident = p; + *nxt_stream_ident = 1; + + return NXT_OK; +} + + static nxt_int_t nxt_rpc_reg_test(nxt_lvlhsh_query_t *lhq, void *data) { @@ -105,8 +128,7 @@ nxt_port_rpc_register_handler_ex(nxt_task_t *task, nxt_port_t *port, nxt_assert(port->pair[0] != -1); - stream = - (uint32_t) nxt_atomic_fetch_add(&nxt_stream_ident, 1) & 0x3FFFFFFF; + stream = nxt_atomic_fetch_add(nxt_stream_ident, 1); reg = nxt_mp_zalloc(port->mem_pool, sizeof(nxt_port_rpc_reg_t) + ex_size); |