From 4f5e11c391c4a8f1b2731aee5ad47bc0c925042a Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 15 Aug 2020 14:09:17 -0700 Subject: fixes #1289 zerotier should have it's own copy of the id hashing code fixes #1288 id allocation can overallocate fixes #1126 consider removing lock from idhash This substantially refactors the id hash code, giving a cleaner API, and eliminating a extra locking as well as some wasteful allocations. The ZeroTier code has it's own copy, that is 64-bit friendly, as the rest of the consumers need only a simpler 32-bit API. --- src/protocol/pair1/pair1_poly.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/protocol/pair1/pair1_poly.c') diff --git a/src/protocol/pair1/pair1_poly.c b/src/protocol/pair1/pair1_poly.c index 950c60f7..fc1bbf6a 100644 --- a/src/protocol/pair1/pair1_poly.c +++ b/src/protocol/pair1/pair1_poly.c @@ -40,7 +40,7 @@ struct pair1poly_sock { nni_sock * sock; nni_atomic_int ttl; nni_mtx mtx; - nni_idhash * pipes; + nni_id_map pipes; nni_list plist; bool started; nni_aio aio_get; @@ -72,7 +72,7 @@ pair1poly_sock_fini(void *arg) pair1poly_sock *s = arg; nni_aio_fini(&s->aio_get); - nni_idhash_fini(s->pipes); + nni_id_map_fini(&s->pipes); nni_mtx_fini(&s->mtx); } @@ -81,9 +81,7 @@ pair1poly_sock_init(void *arg, nni_sock *sock) { pair1poly_sock *s = arg; - if (nni_idhash_init(&s->pipes) != 0) { - return (NNG_ENOMEM); - } + nni_id_map_init(&s->pipes, 0, 0, false); NNI_LIST_INIT(&s->plist, pair1poly_pipe, node); // Raw mode uses this. @@ -196,7 +194,7 @@ pair1poly_pipe_start(void *arg) } id = nni_pipe_id(p->pipe); - if ((rv = nni_idhash_insert(s->pipes, id, p)) != 0) { + if ((rv = nni_id_set(&s->pipes, id, p)) != 0) { nni_mtx_unlock(&s->mtx); return (rv); } @@ -231,7 +229,7 @@ pair1poly_pipe_close(void *arg) nni_aio_close(&p->aio_get); nni_mtx_lock(&s->mtx); - nni_idhash_remove(s->pipes, nni_pipe_id(p->pipe)); + nni_id_remove(&s->pipes, nni_pipe_id(p->pipe)); nni_list_node_remove(&p->node); nni_mtx_unlock(&s->mtx); @@ -311,7 +309,7 @@ pair1poly_sock_get_cb(void *arg) (!nni_list_empty(&s->plist))) { p = nni_list_first(&s->plist); } else { - nni_idhash_find(s->pipes, id, (void **) &p); + p = nni_id_get(&s->pipes, id); } // Try a non-blocking send. If this fails we just discard the -- cgit v1.2.3-70-g09d2