diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/aio.c | 55 | ||||
| -rw-r--r-- | src/core/aio.h | 2 | ||||
| -rw-r--r-- | src/core/defs.h | 4 | ||||
| -rw-r--r-- | src/core/endpt.c | 19 | ||||
| -rw-r--r-- | src/core/event.c | 3 | ||||
| -rw-r--r-- | src/core/event.h | 2 | ||||
| -rw-r--r-- | src/core/idhash.c | 6 | ||||
| -rw-r--r-- | src/core/init.c | 4 | ||||
| -rw-r--r-- | src/core/msgqueue.c | 35 | ||||
| -rw-r--r-- | src/core/pipe.c | 15 | ||||
| -rw-r--r-- | src/core/platform.h | 21 | ||||
| -rw-r--r-- | src/core/random.c | 6 | ||||
| -rw-r--r-- | src/core/socket.c | 41 | ||||
| -rw-r--r-- | src/core/taskq.c | 9 | ||||
| -rw-r--r-- | src/core/thread.c | 20 | ||||
| -rw-r--r-- | src/core/thread.h | 8 | ||||
| -rw-r--r-- | src/core/timer.c | 9 | ||||
| -rw-r--r-- | src/core/transport.c | 5 |
18 files changed, 105 insertions, 159 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index a39c0118..fe9bcde8 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -56,20 +56,14 @@ static nni_list nni_aio_expire_aios; static void nni_aio_expire_add(nni_aio *); -int +void nni_aio_init(nni_aio *aio, nni_cb cb, void *arg) { - int rv; - memset(aio, 0, sizeof(*aio)); - if ((rv = nni_cv_init(&aio->a_cv, &nni_aio_lk)) != 0) { - return (rv); - } + nni_cv_init(&aio->a_cv, &nni_aio_lk); aio->a_expire = NNI_TIME_NEVER; aio->a_init = 1; nni_task_init(NULL, &aio->a_task, cb, arg); - - return (0); } void @@ -350,46 +344,43 @@ nni_aio_expire_loop(void *arg) } } -int -nni_aio_sys_init(void) +void +nni_aio_sys_fini(void) { - int rv; nni_mtx *mtx = &nni_aio_lk; nni_cv * cv = &nni_aio_expire_cv; nni_thr *thr = &nni_aio_expire_thr; - if (((rv = nni_mtx_init(mtx)) != 0) || - ((rv = nni_cv_init(cv, mtx)) != 0) || - ((rv = nni_thr_init(thr, nni_aio_expire_loop, NULL)) != 0)) { - goto fail; + if (nni_aio_expire_run) { + nni_mtx_lock(mtx); + nni_aio_expire_run = 0; + nni_cv_wake(cv); + nni_mtx_unlock(mtx); } - NNI_LIST_INIT(&nni_aio_expire_aios, nni_aio, a_expire_node); - nni_aio_expire_run = 1; - nni_thr_run(thr); - return (0); -fail: nni_thr_fini(thr); nni_cv_fini(cv); nni_mtx_fini(mtx); - return (rv); } -void -nni_aio_sys_fini(void) +int +nni_aio_sys_init(void) { + int rv; nni_mtx *mtx = &nni_aio_lk; nni_cv * cv = &nni_aio_expire_cv; nni_thr *thr = &nni_aio_expire_thr; - if (nni_aio_expire_run) { - nni_mtx_lock(mtx); - nni_aio_expire_run = 0; - nni_cv_wake(cv); - nni_mtx_unlock(mtx); + NNI_LIST_INIT(&nni_aio_expire_aios, nni_aio, a_expire_node); + nni_mtx_init(mtx); + nni_cv_init(cv, mtx); + + if ((rv = nni_thr_init(thr, nni_aio_expire_loop, NULL)) != 0) { + nni_aio_sys_fini(); + return (rv); } - nni_thr_fini(thr); - nni_cv_fini(cv); - nni_mtx_fini(mtx); -}
\ No newline at end of file + nni_aio_expire_run = 1; + nni_thr_run(thr); + return (0); +} diff --git a/src/core/aio.h b/src/core/aio.h index d48442eb..aabb3fa9 100644 --- a/src/core/aio.h +++ b/src/core/aio.h @@ -66,7 +66,7 @@ struct nni_aio { // the supplied argument when the operation is complete. If NULL is // supplied for the callback, then nni_aio_wake is used in its place, // and the aio is used for the argument. -extern int nni_aio_init(nni_aio *, nni_cb, void *); +extern void nni_aio_init(nni_aio *, nni_cb, void *); // nni_aio_fini finalizes the aio, releasing resources (locks) // associated with it. The caller is responsible for ensuring that any diff --git a/src/core/defs.h b/src/core/defs.h index 69fe4843..4d8e6ffb 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -17,9 +17,13 @@ // superior, support for such are not universal. #define NNI_ARG_UNUSED(x) ((void) x); +#ifndef NDEBUG #define NNI_ASSERT(x) \ if (!(x)) \ nni_panic("%s: %d: assert err: %s", __FILE__, __LINE__, #x) +#else +#define NNI_ASSERT(x) +#endif // These types are common but have names shared with user space. typedef struct nng_msg nni_msg; diff --git a/src/core/endpt.c b/src/core/endpt.c index 0ab35ea3..34debc0e 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -57,10 +57,10 @@ nni_ep_sys_init(void) { int rv; - if (((rv = nni_mtx_init(&nni_ep_lk)) != 0) || - ((rv = nni_idhash_init(&nni_eps)) != 0)) { + if ((rv = nni_idhash_init(&nni_eps)) != 0) { return (rv); } + nni_mtx_init(&nni_ep_lk); nni_idhash_set_limits( nni_eps, 1, 0x7fffffff, nni_random() & 0x7fffffff); @@ -152,13 +152,14 @@ nni_ep_create(nni_ep **epp, nni_sock *s, const char *addr, int mode) nni_pipe_ep_list_init(&ep->ep_pipes); - if (((rv = nni_mtx_init(&ep->ep_mtx)) != 0) || - ((rv = nni_cv_init(&ep->ep_cv, &ep->ep_mtx)) != 0) || - ((rv = nni_aio_init(&ep->ep_acc_aio, nni_ep_acc_cb, ep)) != 0) || - ((rv = nni_aio_init(&ep->ep_con_aio, nni_ep_con_cb, ep)) != 0) || - ((rv = nni_aio_init(&ep->ep_tmo_aio, nni_ep_tmo_cb, ep)) != 0) || - ((rv = nni_aio_init(&ep->ep_con_syn, NULL, NULL)) != 0) || - ((rv = ep->ep_ops.ep_init(&ep->ep_data, addr, s, mode)) != 0) || + nni_mtx_init(&ep->ep_mtx); + nni_cv_init(&ep->ep_cv, &ep->ep_mtx); + nni_aio_init(&ep->ep_acc_aio, nni_ep_acc_cb, ep); + nni_aio_init(&ep->ep_con_aio, nni_ep_con_cb, ep); + nni_aio_init(&ep->ep_tmo_aio, nni_ep_tmo_cb, ep); + nni_aio_init(&ep->ep_con_syn, NULL, NULL); + + if (((rv = ep->ep_ops.ep_init(&ep->ep_data, addr, s, mode)) != 0) || ((rv = nni_idhash_alloc(nni_eps, &ep->ep_id, ep)) != 0) || ((rv = nni_sock_ep_add(s, ep)) != 0)) { nni_ep_destroy(ep); diff --git a/src/core/event.c b/src/core/event.c index 79910d80..ab157b02 100644 --- a/src/core/event.c +++ b/src/core/event.c @@ -12,13 +12,12 @@ #include <stdlib.h> #include <string.h> -int +void nni_ev_init(nni_event *event, int type, nni_sock *sock) { memset(event, 0, sizeof(*event)); event->e_type = type; event->e_sock = sock; - return (0); } void diff --git a/src/core/event.h b/src/core/event.h index 6d9a9394..22af096e 100644 --- a/src/core/event.h +++ b/src/core/event.h @@ -28,7 +28,7 @@ struct nng_notify { nni_aio n_aio; }; -extern int nni_ev_init(nni_event *, int, nni_sock *); +extern void nni_ev_init(nni_event *, int, nni_sock *); extern void nni_ev_fini(nni_event *); #endif // CORE_EVENT_H diff --git a/src/core/idhash.c b/src/core/idhash.c index ab6b67e1..03854fc8 100644 --- a/src/core/idhash.c +++ b/src/core/idhash.c @@ -36,15 +36,11 @@ int nni_idhash_init(nni_idhash **hp) { nni_idhash *h; - int rv; if ((h = NNI_ALLOC_STRUCT(h)) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_mtx_init(&h->ih_mtx)) != 0) { - NNI_FREE_STRUCT(h); - return (rv); - } + nni_mtx_init(&h->ih_mtx); h->ih_entries = NULL; h->ih_count = 0; h->ih_load = 0; diff --git a/src/core/init.c b/src/core/init.c index 24a7b118..4025c0f4 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -1,5 +1,5 @@ // -// Copyright 2016 Garrett D'Amore <garrett@damore.org> +// Copyright 2017 Garrett D'Amore <garrett@damore.org> // Copyright 2017 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -39,8 +39,6 @@ nni_init(void) void nni_fini(void) { - // XXX: We should make sure that underlying sockets and - // file descriptors are closed. Details TBD. nni_tran_sys_fini(); nni_pipe_sys_fini(); nni_ep_sys_fini(); diff --git a/src/core/msgqueue.c b/src/core/msgqueue.c index 6530857e..ef7dd5a2 100644 --- a/src/core/msgqueue.c +++ b/src/core/msgqueue.c @@ -39,7 +39,6 @@ int nni_msgq_init(nni_msgq **mqp, unsigned cap) { struct nni_msgq *mq; - int rv; int alloc; // We allocate 2 extra cells in the fifo. One to accommodate a @@ -52,21 +51,18 @@ nni_msgq_init(nni_msgq **mqp, unsigned cap) if ((mq = NNI_ALLOC_STRUCT(mq)) == NULL) { return (NNG_ENOMEM); } + if ((mq->mq_msgs = nni_alloc(sizeof(nng_msg *) * alloc)) == NULL) { + NNI_FREE_STRUCT(mq); + return (NNG_ENOMEM); + } + nni_aio_list_init(&mq->mq_aio_putq); nni_aio_list_init(&mq->mq_aio_getq); nni_aio_list_init(&mq->mq_aio_notify_get); nni_aio_list_init(&mq->mq_aio_notify_put); - if ((rv = nni_mtx_init(&mq->mq_lock)) != 0) { - goto fail; - } - if ((rv = nni_cv_init(&mq->mq_drained, &mq->mq_lock)) != 0) { - goto fail; - } - if ((mq->mq_msgs = nni_alloc(sizeof(nng_msg *) * alloc)) == NULL) { - rv = NNG_ENOMEM; - goto fail; - } + nni_mtx_init(&mq->mq_lock); + nni_cv_init(&mq->mq_drained, &mq->mq_lock); mq->mq_cap = cap; mq->mq_alloc = alloc; @@ -80,15 +76,6 @@ nni_msgq_init(nni_msgq **mqp, unsigned cap) *mqp = mq; return (0); - -fail: - nni_cv_fini(&mq->mq_drained); - nni_mtx_fini(&mq->mq_lock); - if (mq->mq_msgs != NULL) { - nni_free(mq->mq_msgs, sizeof(nng_msg *) * alloc); - } - NNI_FREE_STRUCT(mq); - return (rv); } void @@ -413,9 +400,7 @@ nni_msgq_get_until(nni_msgq *mq, nni_msg **msgp, nni_time expire) nni_aio aio; int rv; - if ((rv = nni_aio_init(&aio, NULL, NULL)) != 0) { - return (rv); - } + nni_aio_init(&aio, NULL, NULL); aio.a_expire = expire; nni_msgq_aio_get(mq, &aio); nni_aio_wait(&aio); @@ -433,9 +418,7 @@ nni_msgq_put_until(nni_msgq *mq, nni_msg *msg, nni_time expire) nni_aio aio; int rv; - if ((rv = nni_aio_init(&aio, NULL, NULL)) != 0) { - return (rv); - } + nni_aio_init(&aio, NULL, NULL); aio.a_expire = expire; aio.a_msg = msg; nni_msgq_aio_put(mq, &aio); diff --git a/src/core/pipe.c b/src/core/pipe.c index 75c4c8d6..cdbeb6a7 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -49,9 +49,10 @@ nni_pipe_sys_init(void) int rv; NNI_LIST_INIT(&nni_pipe_reap_list, nni_pipe, p_reap_node); + nni_mtx_init(&nni_pipe_reap_lk); + nni_cv_init(&nni_pipe_reap_cv, &nni_pipe_reap_lk); + if (((rv = nni_idhash_init(&nni_pipes)) != 0) || - ((rv = nni_mtx_init(&nni_pipe_reap_lk)) != 0) || - ((rv = nni_cv_init(&nni_pipe_reap_cv, &nni_pipe_reap_lk)) != 0) || ((rv = nni_thr_init(&nni_pipe_reap_thr, nni_pipe_reaper, 0)) != 0)) { return (rv); @@ -240,11 +241,11 @@ nni_pipe_create(nni_ep *ep, void *tdata) NNI_LIST_NODE_INIT(&p->p_sock_node); NNI_LIST_NODE_INIT(&p->p_ep_node); - if (((rv = nni_mtx_init(&p->p_mtx)) != 0) || - ((rv = nni_cv_init(&p->p_cv, &p->p_mtx)) != 0) || - ((rv = nni_aio_init(&p->p_start_aio, nni_pipe_start_cb, p)) != - 0) || - ((rv = nni_idhash_alloc(nni_pipes, &p->p_id, p)) != 0) || + nni_mtx_init(&p->p_mtx); + nni_cv_init(&p->p_cv, &p->p_mtx); + nni_aio_init(&p->p_start_aio, nni_pipe_start_cb, p); + + if (((rv = nni_idhash_alloc(nni_pipes, &p->p_id, p)) != 0) || ((rv = nni_ep_pipe_add(ep, p)) != 0) || ((rv = nni_sock_pipe_add(sock, p)) != 0)) { nni_pipe_destroy(p); diff --git a/src/core/platform.h b/src/core/platform.h index 7acf16ef..f6f0b974 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -85,10 +85,9 @@ typedef struct nni_plat_thr nni_plat_thr; // Threading & Synchronization Support // -// nni_plat_mtx_init initializes a mutex structure. This may require dynamic -// allocation, depending on the platform. It can return NNG_ENOMEM if that -// fails. An initialized mutex must be distinguishable from zeroed memory. -extern int nni_plat_mtx_init(nni_plat_mtx *); +// nni_plat_mtx_init initializes a mutex structure. An initialized mutex must +// be distinguishable from zeroed memory. +extern void nni_plat_mtx_init(nni_plat_mtx *); // nni_plat_mtx_fini destroys the mutex and releases any resources allocated // for it's use. If the mutex is zeroed memory, this should do nothing. @@ -99,20 +98,14 @@ extern void nni_plat_mtx_fini(nni_plat_mtx *); extern void nni_plat_mtx_lock(nni_plat_mtx *); // nni_plat_mtx_unlock unlocks the mutex. This can only be performed by the -// threadthat owned the mutex. +// thread that owned the mutex. extern void nni_plat_mtx_unlock(nni_plat_mtx *); -// nni_plat_mtx_tryenter tries to lock the mutex. If it can't, it may return -// NNG_EBUSY if the mutex is already owned. -extern int nni_plat_mtx_trylock(nni_plat_mtx *); - // nni_plat_cv_init initializes a condition variable. We require a mutex be // supplied with it, and that mutex must always be held when performing any -// operations on the condition variable (other than fini.) This may require -// dynamic allocation, and if so this operation may fail with NNG_ENOMEM. -// As with mutexes, an initialized mutex should be distinguishable from -// zeroed memory. -extern int nni_plat_cv_init(nni_plat_cv *, nni_plat_mtx *); +// operations on the condition variable (other than fini.) As with mutexes, an +// initialized mutex should be distinguishable from zeroed memory. +extern void nni_plat_cv_init(nni_plat_cv *, nni_plat_mtx *); // nni_plat_cv_fini releases all resources associated with condition variable. // If the cv points to just zeroed memory (was never initialized), it does diff --git a/src/core/random.c b/src/core/random.c index eb0b4fc2..febd0848 100644 --- a/src/core/random.c +++ b/src/core/random.c @@ -170,12 +170,8 @@ nni_random_sys_init(void) { // minimally, grab the system clock nni_isaac_ctx *ctx = &nni_random_ctx; - int rv; - - if ((rv = nni_mtx_init(&ctx->mx)) != 0) { - return (rv); - } + nni_mtx_init(&ctx->mx); nni_plat_seed_prng(ctx->randrsl, sizeof(ctx->randrsl)); nni_isaac_randinit(ctx, 1); return (0); diff --git a/src/core/socket.c b/src/core/socket.c index 6a243650..9aa89a2d 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -231,7 +231,6 @@ nni_notify * nni_sock_notify(nni_sock *sock, int type, nng_notify_func fn, void *arg) { nni_notify *notify; - int rv; if ((notify = NNI_ALLOC_STRUCT(notify)) == NULL) { return (NULL); @@ -244,31 +243,19 @@ nni_sock_notify(nni_sock *sock, int type, nng_notify_func fn, void *arg) switch (type) { case NNG_EV_CAN_RCV: - rv = nni_aio_init(¬ify->n_aio, nni_sock_canrecv_cb, notify); - if (rv != 0) { - goto fail; - } + nni_aio_init(¬ify->n_aio, nni_sock_canrecv_cb, notify); nni_msgq_aio_notify_get(sock->s_urq, ¬ify->n_aio); break; case NNG_EV_CAN_SND: - rv = nni_aio_init(¬ify->n_aio, nni_sock_cansend_cb, notify); - if (rv != 0) { - goto fail; - } + nni_aio_init(¬ify->n_aio, nni_sock_cansend_cb, notify); nni_msgq_aio_notify_put(sock->s_uwq, ¬ify->n_aio); break; default: - rv = NNG_ENOTSUP; - goto fail; - break; + NNI_FREE_STRUCT(notify); + return (NULL); } return (notify); - -fail: - nni_aio_fini(¬ify->n_aio); - NNI_FREE_STRUCT(notify); - return (NULL); } void @@ -343,13 +330,13 @@ nni_sock_create(nni_sock **sp, const nni_proto *proto) NNI_LIST_NODE_INIT(&s->s_node); nni_pipe_sock_list_init(&s->s_pipes); nni_ep_list_init(&s->s_eps); + nni_mtx_init(&s->s_mx); + nni_cv_init(&s->s_cv, &s->s_mx); + nni_cv_init(&s->s_close_cv, &nni_sock_lk); + nni_ev_init(&s->s_recv_ev, NNG_EV_CAN_RCV, s); + nni_ev_init(&s->s_send_ev, NNG_EV_CAN_SND, s); - if (((rv = nni_mtx_init(&s->s_mx)) != 0) || - ((rv = nni_cv_init(&s->s_cv, &s->s_mx)) != 0) || - ((rv = nni_cv_init(&s->s_close_cv, &nni_sock_lk)) != 0) || - ((rv = nni_ev_init(&s->s_recv_ev, NNG_EV_CAN_RCV, s)) != 0) || - ((rv = nni_ev_init(&s->s_send_ev, NNG_EV_CAN_SND, s)) != 0) || - ((rv = nni_msgq_init(&s->s_uwq, 0)) != 0) || + if (((rv = nni_msgq_init(&s->s_uwq, 0)) != 0) || ((rv = nni_msgq_init(&s->s_urq, 0)) != 0) || ((rv = s->s_sock_ops.sock_init(&s->s_data, s)) != 0)) { nni_sock_destroy(s); @@ -365,8 +352,9 @@ nni_sock_sys_init(void) int rv; NNI_LIST_INIT(&nni_sock_list, nni_sock, s_node); - if (((rv = nni_idhash_init(&nni_sock_hash)) != 0) || - ((rv = nni_mtx_init(&nni_sock_lk)) != 0)) { + nni_mtx_init(&nni_sock_lk); + + if ((rv = nni_idhash_init(&nni_sock_hash)) != 0) { nni_sock_sys_fini(); } else { nni_idhash_set_limits(nni_sock_hash, 1, 0x7fffffff, 1); @@ -562,6 +550,9 @@ nni_sock_closeall(void) { nni_sock *s; + if (nni_sock_hash == NULL) { + return; + } for (;;) { nni_mtx_lock(&nni_sock_lk); if ((s = nni_list_first(&nni_sock_list)) == NULL) { diff --git a/src/core/taskq.c b/src/core/taskq.c index e0fc456c..d0f04e8a 100644 --- a/src/core/taskq.c +++ b/src/core/taskq.c @@ -85,12 +85,9 @@ nni_taskq_init(nni_taskq **tqp, int nthr) tq->tq_nthreads = nthr; NNI_LIST_INIT(&tq->tq_tasks, nni_task, task_node); - if (((rv = nni_mtx_init(&tq->tq_mtx)) != 0) || - ((rv = nni_cv_init(&tq->tq_sched_cv, &tq->tq_mtx)) != 0) || - ((rv = nni_cv_init(&tq->tq_wait_cv, &tq->tq_mtx)) != 0)) { - nni_taskq_fini(tq); - return (rv); - } + nni_mtx_init(&tq->tq_mtx); + nni_cv_init(&tq->tq_sched_cv, &tq->tq_mtx); + nni_cv_init(&tq->tq_wait_cv, &tq->tq_mtx); for (i = 0; i < nthr; i++) { tq->tq_threads[i].tqt_tq = tq; diff --git a/src/core/thread.c b/src/core/thread.c index 6c3bd9f3..54c9c7d2 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -9,10 +9,10 @@ #include "core/nng_impl.h" -int +void nni_mtx_init(nni_mtx *mtx) { - return (nni_plat_mtx_init(mtx)); + nni_plat_mtx_init(mtx); } void @@ -33,10 +33,10 @@ nni_mtx_unlock(nni_mtx *mtx) nni_plat_mtx_unlock(mtx); } -int +void nni_cv_init(nni_cv *cv, nni_mtx *mtx) { - return (nni_plat_cv_init(cv, mtx)); + nni_plat_cv_init(cv, mtx); } void @@ -110,15 +110,9 @@ nni_thr_init(nni_thr *thr, nni_thr_func fn, void *arg) thr->fn = fn; thr->arg = arg; - if ((rv = nni_plat_mtx_init(&thr->mtx)) != 0) { - thr->done = 1; - return (rv); - } - if ((rv = nni_plat_cv_init(&thr->cv, &thr->mtx)) != 0) { - nni_plat_mtx_fini(&thr->mtx); - thr->done = 1; - return (rv); - } + nni_plat_mtx_init(&thr->mtx); + nni_plat_cv_init(&thr->cv, &thr->mtx); + if (fn == NULL) { thr->init = 1; thr->done = 1; diff --git a/src/core/thread.h b/src/core/thread.h index 94b2a984..ee83b196 100644 --- a/src/core/thread.h +++ b/src/core/thread.h @@ -1,5 +1,6 @@ // // Copyright 2017 Garrett D'Amore <garrett@damore.org> +// Copyright 2017 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -25,9 +26,8 @@ struct nni_thr { int init; }; -// nni_mtx_init initializes the mutex. (Win32 programmers take note; -// our mutexes are actually CriticalSections on Win32.) -extern int nni_mtx_init(nni_mtx *mtx); +// nni_mtx_init initializes the mutex. +extern void nni_mtx_init(nni_mtx *mtx); // nni_mtx_fini destroys the mutex and releases any resources used by it. extern void nni_mtx_fini(nni_mtx *mtx); @@ -43,7 +43,7 @@ extern void nni_mtx_unlock(nni_mtx *mtx); // nni_cv_init initializes the condition variable. The mutex supplied // must always be locked with the condition variable. -extern int nni_cv_init(nni_cv *cv, nni_mtx *); +extern void nni_cv_init(nni_cv *cv, nni_mtx *); // nni_cv_fini releases resources associated with the condition variable, // which must not be in use at the time. diff --git a/src/core/timer.c b/src/core/timer.c index 73bc7604..7608f7d5 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -40,10 +40,11 @@ nni_timer_sys_init(void) memset(timer, 0, sizeof(*timer)); NNI_LIST_INIT(&timer->t_entries, nni_timer_node, t_node); - if (((rv = nni_mtx_init(&timer->t_mx)) != 0) || - ((rv = nni_cv_init(&timer->t_sched_cv, &timer->t_mx)) != 0) || - ((rv = nni_cv_init(&timer->t_wait_cv, &timer->t_mx)) != 0) || - ((rv = nni_thr_init(&timer->t_thr, nni_timer_loop, timer)) != 0)) { + nni_mtx_init(&timer->t_mx); + nni_cv_init(&timer->t_sched_cv, &timer->t_mx); + nni_cv_init(&timer->t_wait_cv, &timer->t_mx); + + if ((rv = nni_thr_init(&timer->t_thr, nni_timer_loop, timer)) != 0) { nni_timer_sys_fini(); return (rv); } diff --git a/src/core/transport.c b/src/core/transport.c index 278c7d1e..6f73a6b2 100644 --- a/src/core/transport.c +++ b/src/core/transport.c @@ -84,8 +84,9 @@ nni_tran_sys_init(void) int rv; NNI_LIST_INIT(&nni_tran_list, nni_transport, t_node); - if (((rv = nni_mtx_init(&nni_tran_lk)) != 0) || - ((rv = nni_tran_register(&nni_inproc_tran)) != 0) || + nni_mtx_init(&nni_tran_lk); + + if (((rv = nni_tran_register(&nni_inproc_tran)) != 0) || ((rv = nni_tran_register(&nni_ipc_tran)) != 0) || ((rv = nni_tran_register(&nni_tcp_tran)) != 0)) { nni_tran_sys_fini(); |
