aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/pair1/pair1_poly.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-08-15 14:09:17 -0700
committerGarrett D'Amore <garrett@damore.org>2020-08-16 23:07:35 -0700
commit4f5e11c391c4a8f1b2731aee5ad47bc0c925042a (patch)
tree640aef66eb7e0030a2833bc9bba3246edb29d074 /src/protocol/pair1/pair1_poly.c
parent750662d4aab305d8a3d48bfa6edfc4dac4018881 (diff)
downloadnng-4f5e11c391c4a8f1b2731aee5ad47bc0c925042a.tar.gz
nng-4f5e11c391c4a8f1b2731aee5ad47bc0c925042a.tar.bz2
nng-4f5e11c391c4a8f1b2731aee5ad47bc0c925042a.zip
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.
Diffstat (limited to 'src/protocol/pair1/pair1_poly.c')
-rw-r--r--src/protocol/pair1/pair1_poly.c14
1 files changed, 6 insertions, 8 deletions
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