aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/survey0/respond.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/survey0/respond.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/survey0/respond.c')
-rw-r--r--src/protocol/survey0/respond.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/protocol/survey0/respond.c b/src/protocol/survey0/respond.c
index b414c189..7583c4d8 100644
--- a/src/protocol/survey0/respond.c
+++ b/src/protocol/survey0/respond.c
@@ -50,7 +50,7 @@ struct resp0_ctx {
struct resp0_sock {
nni_mtx mtx;
nni_atomic_int ttl;
- nni_idhash * pipes;
+ nni_id_map pipes;
resp0_ctx ctx;
nni_list recvpipes;
nni_list recvq;
@@ -181,7 +181,7 @@ resp0_ctx_send(void *arg, nni_aio *aio)
return;
}
- if (nni_idhash_find(s->pipes, pid, (void **) &p) != 0) {
+ if ((p = nni_id_get(&s->pipes, pid)) == NULL) {
// Surveyor has left the building. Just discard the reply.
nni_mtx_unlock(&s->mtx);
nni_aio_set_msg(aio, NULL);
@@ -213,7 +213,7 @@ resp0_sock_fini(void *arg)
{
resp0_sock *s = arg;
- nni_idhash_fini(s->pipes);
+ nni_id_map_fini(&s->pipes);
resp0_ctx_fini(&s->ctx);
nni_pollable_fini(&s->writable);
nni_pollable_fini(&s->readable);
@@ -224,15 +224,11 @@ static int
resp0_sock_init(void *arg, nni_sock *nsock)
{
resp0_sock *s = arg;
- int rv;
NNI_ARG_UNUSED(nsock);
nni_mtx_init(&s->mtx);
- if ((rv = nni_idhash_init(&s->pipes)) != 0) {
- resp0_sock_fini(s);
- return (rv);
- }
+ nni_id_map_init(&s->pipes, 0, 0, false);
NNI_LIST_INIT(&s->recvq, resp0_ctx, rqnode);
NNI_LIST_INIT(&s->recvpipes, resp0_pipe, rnode);
@@ -316,7 +312,7 @@ resp0_pipe_start(void *arg)
}
nni_mtx_lock(&s->mtx);
- rv = nni_idhash_insert(s->pipes, p->id, p);
+ rv = nni_id_set(&s->pipes, p->id, p);
nni_mtx_unlock(&s->mtx);
if (rv != 0) {
return (rv);
@@ -354,7 +350,7 @@ resp0_pipe_close(void *arg)
// which we will happily discard.
nni_pollable_raise(&s->writable);
}
- nni_idhash_remove(s->pipes, p->id);
+ nni_id_remove(&s->pipes, p->id);
nni_mtx_unlock(&s->mtx);
}