From c50111c825d2a6724ea49ea72cee0eeb420ec432 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 9 Jun 2017 06:36:19 -0700 Subject: Eliminate pipes global idhash. --- src/core/init.c | 33 --------------------------------- src/core/init.h | 5 ----- src/core/pipe.c | 24 ++++++++++++------------ 3 files changed, 12 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/core/init.c b/src/core/init.c index 3339b532..c2fe3aff 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -11,12 +11,6 @@ #include #include -nni_idhash *nni_pipes; -nni_mtx *nni_idlock; - -static nni_idhash nni_pipes_x; -static nni_mtx nni_idlock_x; - static int nni_init_helper(void) { @@ -55,31 +49,6 @@ nni_init_helper(void) nni_taskq_sys_fini(); return (rv); } - if ((rv = nni_mtx_init(&nni_idlock_x)) != 0) { - nni_pipe_sys_fini(); - nni_ep_sys_fini(); - nni_sock_sys_fini(); - nni_random_sys_fini(); - nni_timer_sys_fini(); - nni_taskq_sys_fini(); - return (rv); - } - if ((rv = nni_idhash_init(&nni_pipes_x)) != 0) { - nni_mtx_fini(&nni_idlock_x); - nni_pipe_sys_fini(); - nni_ep_sys_fini(); - nni_sock_sys_fini(); - nni_random_sys_fini(); - nni_timer_sys_fini(); - nni_taskq_sys_fini(); - return (rv); - } - nni_idhash_set_limits(&nni_pipes_x, 1, 0x7fffffff, - (nni_random() & 0x7ffffffe) + 1); - - nni_idlock = &nni_idlock_x; - nni_pipes = &nni_pipes_x; - nni_tran_sys_init(); return (0); } @@ -95,8 +64,6 @@ nni_init(void) void nni_fini(void) { - nni_idhash_fini(&nni_pipes_x); - nni_mtx_fini(&nni_idlock_x); nni_tran_sys_fini(); nni_ep_sys_fini(); nni_sock_sys_fini(); diff --git a/src/core/init.h b/src/core/init.h index 70663c65..ffcebf64 100644 --- a/src/core/init.h +++ b/src/core/init.h @@ -21,9 +21,4 @@ int nni_init(void); // that all resources used by the library are released back to the system. void nni_fini(void); -// Private hash tables matching IDs to values. Consumers need to use the -// nni_idlock to protect access to these. -extern nni_mtx *nni_idlock; -extern nni_idhash *nni_pipes; - #endif // CORE_INIT_H diff --git a/src/core/pipe.c b/src/core/pipe.c index dd597feb..58703814 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -14,7 +14,7 @@ // Operations on pipes (to the transport) are generally blocking operations, // performed in the context of the protocol. -static nni_objhash *nni_allpipes; +static nni_objhash *nni_pipes; static void * nni_pipe_ctor(uint32_t id) @@ -61,7 +61,7 @@ nni_pipe_sys_init(void) { int rv; - rv = nni_objhash_init(&nni_allpipes, nni_pipe_ctor, nni_pipe_dtor); + rv = nni_objhash_init(&nni_pipes, nni_pipe_ctor, nni_pipe_dtor); if (rv != 0) { return (rv); @@ -74,8 +74,8 @@ nni_pipe_sys_init(void) void nni_pipe_sys_fini(void) { - nni_objhash_fini(nni_allpipes); - nni_allpipes = NULL; + nni_objhash_fini(nni_pipes); + nni_pipes = NULL; } @@ -107,7 +107,7 @@ nni_pipe_incref(nni_pipe *p) int rv; nni_pipe *scratch; - rv = nni_objhash_find(nni_allpipes, p->p_id, (void **) &scratch); + rv = nni_objhash_find(nni_pipes, p->p_id, (void **) &scratch); NNI_ASSERT(rv == 0); NNI_ASSERT(p == scratch); } @@ -116,7 +116,7 @@ nni_pipe_incref(nni_pipe *p) void nni_pipe_decref(nni_pipe *p) { - nni_objhash_unref(nni_allpipes, p->p_id); + nni_objhash_unref(nni_pipes, p->p_id); } @@ -146,7 +146,7 @@ nni_pipe_close(nni_pipe *p) // Let the socket (and endpoint) know we have closed. nni_sock_pipe_closed(sock, p); - nni_objhash_unref(nni_allpipes, p->p_id); + nni_objhash_unref(nni_pipes, p->p_id); } @@ -164,7 +164,7 @@ nni_pipe_create(nni_pipe **pp, nni_ep *ep, nni_sock *sock, nni_tran *tran) int rv; uint32_t id; - rv = nni_objhash_alloc(nni_allpipes, &id, (void **) &p); + rv = nni_objhash_alloc(nni_pipes, &id, (void **) &p); if (rv != 0) { return (rv); } @@ -176,12 +176,12 @@ nni_pipe_create(nni_pipe **pp, nni_ep *ep, nni_sock *sock, nni_tran *tran) // Initialize the transport pipe data. if ((rv = p->p_tran_ops.p_init(&p->p_tran_data)) != 0) { - nni_objhash_unref(nni_allpipes, p->p_id); + nni_objhash_unref(nni_pipes, p->p_id); return (rv); } if ((rv = nni_sock_pipe_add(sock, p)) != 0) { - nni_objhash_unref(nni_allpipes, p->p_id); + nni_objhash_unref(nni_pipes, p->p_id); return (rv); } @@ -195,7 +195,7 @@ nni_pipe_destroy(nni_pipe *p) { NNI_ASSERT(p->p_refcnt == 0); - nni_objhash_unref(nni_allpipes, p->p_id); + nni_objhash_unref(nni_pipes, p->p_id); } @@ -216,7 +216,7 @@ nni_pipe_start(nni_pipe *p) int rv; nni_pipe *scratch; - rv = nni_objhash_find(nni_allpipes, p->p_id, (void **) &scratch); + rv = nni_objhash_find(nni_pipes, p->p_id, (void **) &scratch); if (rv != 0) { return (rv); } -- cgit v1.2.3-70-g09d2