aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/pubsub/sub.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-15 21:59:55 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-16 18:31:42 -0700
commita9633313ec8e578c805cd53b37ba3360d83157bc (patch)
tree14d32c4031ea1c8508a75469407ca77e353fa315 /src/protocol/pubsub/sub.c
parente7e2a6c14f0317eb77711951c6f1a650d4013dfe (diff)
downloadnng-a9633313ec8e578c805cd53b37ba3360d83157bc.tar.gz
nng-a9633313ec8e578c805cd53b37ba3360d83157bc.tar.bz2
nng-a9633313ec8e578c805cd53b37ba3360d83157bc.zip
Provide versions of mutex, condvar, and aio init that never fail.
If the underlying platform fails (FreeBSD is the only one I'm aware of that does this!), we use a global lock or condition variable instead. This means that our lock initializers never ever fail. Probably we could eliminate most of this for Linux and Darwin, since on those platforms, mutex and condvar initialization reasonably never fails. Initial benchmarks show little difference either way -- so we can revisit (optimize) later. This removes a lot of otherwise untested code in error cases and so forth, improving coverage and resilience in the face of allocation failures. Platforms other than POSIX should follow a similar pattern if they need this. (VxWorks, I'm thinking of you.) Most sane platforms won't have an issue here, since normally these initializations do not need to allocate memory. (Reportedly, even FreeBSD has plans to "fix" this in libthr2.) While here, some bugs were fixed in initialization & teardown. The fallback code is properly tested with dedicated test cases.
Diffstat (limited to 'src/protocol/pubsub/sub.c')
-rw-r--r--src/protocol/pubsub/sub.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/protocol/pubsub/sub.c b/src/protocol/pubsub/sub.c
index 53f01e0f..78b9d157 100644
--- a/src/protocol/pubsub/sub.c
+++ b/src/protocol/pubsub/sub.c
@@ -95,16 +95,13 @@ static int
nni_sub_pipe_init(void **spp, nni_pipe *pipe, void *ssock)
{
nni_sub_pipe *sp;
- int rv;
if ((sp = NNI_ALLOC_STRUCT(sp)) == NULL) {
return (NNG_ENOMEM);
}
- if (((rv = nni_aio_init(&sp->aio_putq, nni_sub_putq_cb, sp)) != 0) ||
- ((rv = nni_aio_init(&sp->aio_recv, nni_sub_recv_cb, sp)) != 0)) {
- nni_sub_pipe_fini(sp);
- return (rv);
- }
+ nni_aio_init(&sp->aio_putq, nni_sub_putq_cb, sp);
+ nni_aio_init(&sp->aio_recv, nni_sub_recv_cb, sp);
+
sp->pipe = pipe;
sp->sub = ssock;
*spp = sp;