aboutsummaryrefslogtreecommitdiff
path: root/src/core/pipe.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2021-12-06 21:09:55 -0500
committerGarrett D'Amore <garrett@damore.org>2021-12-06 21:09:55 -0500
commit037d26a902a3cd5016052c76a6747e40c1a0df50 (patch)
treef76ed1eabcffa862d93ffe6ee3d53c6a0ae472c4 /src/core/pipe.c
parent21528dfe0998d056222191a4abe53d8d9f1286e3 (diff)
downloadnng-037d26a902a3cd5016052c76a6747e40c1a0df50.tar.gz
nng-037d26a902a3cd5016052c76a6747e40c1a0df50.tar.bz2
nng-037d26a902a3cd5016052c76a6747e40c1a0df50.zip
ID map static initialization support.
This also arranges to clean up the maps at nng_fini time.
Diffstat (limited to 'src/core/pipe.c')
-rw-r--r--src/core/pipe.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/src/core/pipe.c b/src/core/pipe.c
index 2b66ad81..36b77d91 100644
--- a/src/core/pipe.c
+++ b/src/core/pipe.c
@@ -19,8 +19,9 @@
// Operations on pipes (to the transport) are generally blocking operations,
// performed in the context of the protocol.
-static nni_id_map pipes;
-static nni_mtx pipes_lk;
+static nni_id_map pipes =
+ NNI_ID_MAP_INITIALIZER(1, 0x7fffffff, NNI_ID_FLAG_RANDOM);
+static nni_mtx pipes_lk = NNI_MTX_INITIALIZER;
static void pipe_destroy(void *);
@@ -29,24 +30,6 @@ static nni_reap_list pipe_reap_list = {
.rl_func = pipe_destroy,
};
-void
-nni_pipe_sys_init(void)
-{
- nni_mtx_init(&pipes_lk);
-
- // Pipe IDs need their high bit clear, and we want
- // them to start at a random value.
- nni_id_map_init(&pipes, 1, 0x7fffffff, true);
-}
-
-void
-nni_pipe_sys_fini(void)
-{
- nni_reap_drain();
- nni_mtx_fini(&pipes_lk);
- nni_id_map_fini(&pipes);
-}
-
static void
pipe_destroy(void *arg)
{
@@ -248,7 +231,7 @@ pipe_create(nni_pipe **pp, nni_sock *sock, nni_sp_tran *tran, void *tran_data)
nni_pipe *p;
int rv;
void *sock_data = nni_sock_proto_data(sock);
- nni_proto_pipe_ops *pops = nni_sock_proto_pipe_ops(sock);
+ nni_proto_pipe_ops *pops = nni_sock_proto_pipe_ops(sock);
size_t sz;
sz = NNI_ALIGN_UP(sizeof(*p)) + pops->pipe_size;