diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-17 19:36:15 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-17 19:36:15 -0800 |
| commit | a00f1938497e629187ebc6035e03bb58d1017730 (patch) | |
| tree | 36f9694c9d1d94ef64f9686da3bf8cd971877f15 /src/core/pipe.c | |
| parent | eb3b131db73610274a41f04d8fd6b7cf879cc016 (diff) | |
| download | nng-a00f1938497e629187ebc6035e03bb58d1017730.tar.gz nng-a00f1938497e629187ebc6035e03bb58d1017730.tar.bz2 nng-a00f1938497e629187ebc6035e03bb58d1017730.zip | |
Pipe IDs are now tracked by hash table for performance.
This gives a better idea of pipe ID uniqueness, and is a step towards
conversion of the API to use IDs instead of pointers.
Diffstat (limited to 'src/core/pipe.c')
| -rw-r--r-- | src/core/pipe.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/core/pipe.c b/src/core/pipe.c index 0633dea9..6cc93d98 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -121,6 +121,7 @@ nni_pipe_create(nni_pipe **pp, nni_ep *ep) p->p_tran_data = NULL; p->p_proto_data = NULL; p->p_active = 0; + p->p_id = 0; NNI_LIST_NODE_INIT(&p->p_node); // Make a copy of the transport ops. We can override entry points @@ -168,7 +169,6 @@ nni_pipe_start(nni_pipe *pipe) { int rv; int i; - int collide; nni_sock *sock = pipe->p_sock; nni_mtx_lock(&sock->s_mx); @@ -184,23 +184,16 @@ nni_pipe_start(nni_pipe *pipe) return (NNG_EPROTO); } - do { - // We generate a new pipe ID, but we make sure it does not - // collide with any we already have. This can only normally - // happen if we wrap -- i.e. we've had 4 billion or so pipes. - // XXX: consider making this a hash table!! - nni_pipe *check; - pipe->p_id = nni_random() & 0x7FFFFFFF; - collide = 0; - NNI_LIST_FOREACH (&sock->s_pipes, check) { - if ((pipe != check) && (check->p_id == pipe->p_id)) { - collide = 1; - break; - } - } - } while (collide); + rv = nni_idhash_alloc(sock->s_pipes_by_id, &pipe->p_id, pipe); + if (rv != 0) { + nni_pipe_bail(pipe); + nni_mtx_unlock(&sock->s_mx); + return (rv); + } if ((rv = sock->s_pipe_ops.pipe_add(pipe->p_proto_data)) != 0) { + nni_idhash_remove(sock->s_pipes_by_id, pipe->p_id); + pipe->p_id = 0; nni_pipe_bail(pipe); nni_mtx_unlock(&sock->s_mx); return (rv); |
