aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-06-21 14:04:16 -0700
committerGarrett D'Amore <garrett@damore.org>2017-06-21 14:04:16 -0700
commit763b8deee1fd38566b85d4745a83adae245d9b26 (patch)
tree00404dbc8e6c07fc5a9d8e07f353beff3adefd5a /src/core
parentf81c7e8cc84bd43bfc3cc5e41f773a0078870312 (diff)
downloadnng-763b8deee1fd38566b85d4745a83adae245d9b26.tar.gz
nng-763b8deee1fd38566b85d4745a83adae245d9b26.tar.bz2
nng-763b8deee1fd38566b85d4745a83adae245d9b26.zip
Make APIs for holding references more consistent.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/endpt.c18
-rw-r--r--src/core/endpt.h3
-rw-r--r--src/core/objhash.c4
-rw-r--r--src/core/pipe.c8
-rw-r--r--src/core/pipe.h4
-rw-r--r--src/core/socket.c17
-rw-r--r--src/core/socket.h3
7 files changed, 37 insertions, 20 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c
index 91ddb318..326bac48 100644
--- a/src/core/endpt.c
+++ b/src/core/endpt.c
@@ -39,7 +39,7 @@ nni_ep_sys_fini(void)
int
-nni_ep_hold(nni_ep **epp, uint32_t id)
+nni_ep_find(nni_ep **epp, uint32_t id)
{
int rv;
nni_ep *ep;
@@ -67,6 +67,16 @@ nni_ep_hold(nni_ep **epp, uint32_t id)
void
+nni_ep_hold(nni_ep *ep)
+{
+ int rv;
+
+ rv = nni_objhash_find(nni_eps, ep->ep_id, NULL);
+ NNI_ASSERT(rv == 0);
+}
+
+
+void
nni_ep_rele(nni_ep *ep)
{
nni_objhash_unref(nni_eps, ep->ep_id);
@@ -226,11 +236,7 @@ nni_ep_connect(nni_ep *ep, nni_pipe **pp)
int
nni_ep_add_pipe(nni_ep *ep, nni_pipe *pipe)
{
- int rv;
-
- if ((rv = nni_ep_hold(NULL, ep->ep_id)) != 0) {
- return (rv);
- }
+ nni_ep_hold(ep);
nni_mtx_lock(&ep->ep_mtx);
if (ep->ep_close) {
nni_mtx_unlock(&ep->ep_mtx);
diff --git a/src/core/endpt.h b/src/core/endpt.h
index 7991a916..2f2a5067 100644
--- a/src/core/endpt.h
+++ b/src/core/endpt.h
@@ -42,7 +42,8 @@ struct nni_ep {
extern int nni_ep_sys_init(void);
extern void nni_ep_sys_fini(void);
-extern int nni_ep_hold(nni_ep **, uint32_t);
+extern int nni_ep_find(nni_ep **, uint32_t);
+extern void nni_ep_hold(nni_ep *);
extern void nni_ep_rele(nni_ep *);
extern uint32_t nni_ep_id(nni_ep *);
extern int nni_ep_create(nni_ep **, nni_sock *, const char *);
diff --git a/src/core/objhash.c b/src/core/objhash.c
index 94c42dcf..5ee5f5c7 100644
--- a/src/core/objhash.c
+++ b/src/core/objhash.c
@@ -145,7 +145,9 @@ nni_objhash_find(nni_objhash *oh, uint32_t id, void **valp)
node = nni_objhash_find_node(oh, id);
if ((node != NULL) && (node->on_val != NULL)) {
- *valp = node->on_val;
+ if (valp != NULL) {
+ *valp = node->on_val;
+ }
node->on_refcnt++;
rv = 0;
} else {
diff --git a/src/core/pipe.c b/src/core/pipe.c
index 58703814..80b39171 100644
--- a/src/core/pipe.c
+++ b/src/core/pipe.c
@@ -102,19 +102,17 @@ nni_pipe_aio_send(nni_pipe *p, nni_aio *aio)
void
-nni_pipe_incref(nni_pipe *p)
+nni_pipe_hold(nni_pipe *p)
{
int rv;
- nni_pipe *scratch;
- rv = nni_objhash_find(nni_pipes, p->p_id, (void **) &scratch);
+ rv = nni_objhash_find(nni_pipes, p->p_id, NULL);
NNI_ASSERT(rv == 0);
- NNI_ASSERT(p == scratch);
}
void
-nni_pipe_decref(nni_pipe *p)
+nni_pipe_rele(nni_pipe *p)
{
nni_objhash_unref(nni_pipes, p->p_id);
}
diff --git a/src/core/pipe.h b/src/core/pipe.h
index e9ce89b3..379b1d8a 100644
--- a/src/core/pipe.h
+++ b/src/core/pipe.h
@@ -42,8 +42,8 @@ extern int nni_pipe_aio_send(nni_pipe *, nni_aio *);
// Pipe operations that protocols use.
extern uint32_t nni_pipe_id(nni_pipe *);
extern void nni_pipe_close(nni_pipe *);
-extern void nni_pipe_incref(nni_pipe *);
-extern void nni_pipe_decref(nni_pipe *);
+extern void nni_pipe_hold(nni_pipe *);
+extern void nni_pipe_rele(nni_pipe *);
// Used only by the socket core - as we don't wish to expose the details
// of the pipe structure outside of pipe.c.
diff --git a/src/core/socket.c b/src/core/socket.c
index ee653780..195bbcf3 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -39,7 +39,7 @@ nni_sock_recvq(nni_sock *s)
int
-nni_sock_hold(nni_sock **sockp, uint32_t id)
+nni_sock_find(nni_sock **sockp, uint32_t id)
{
int rv;
nni_sock *sock;
@@ -66,6 +66,16 @@ nni_sock_hold(nni_sock **sockp, uint32_t id)
void
+nni_sock_hold(nni_sock *sock)
+{
+ int rv;
+
+ rv = nni_objhash_find(nni_socks, sock->s_id, NULL);
+ NNI_ASSERT(rv == 0);
+}
+
+
+void
nni_sock_rele(nni_sock *sock)
{
nni_objhash_unref(nni_socks, sock->s_id);
@@ -615,9 +625,8 @@ nni_sock_add_ep(nni_sock *sock, nni_ep *ep)
{
int rv;
- if ((rv = nni_sock_hold(NULL, sock->s_id)) != 0) {
- return (rv);
- }
+ nni_sock_hold(sock);
+
nni_mtx_lock(&sock->s_mx);
if (sock->s_closing) {
nni_mtx_unlock(&sock->s_mx);
diff --git a/src/core/socket.h b/src/core/socket.h
index 15183f6b..68f05705 100644
--- a/src/core/socket.h
+++ b/src/core/socket.h
@@ -63,7 +63,8 @@ struct nni_socket {
extern int nni_sock_sys_init(void);
extern void nni_sock_sys_fini(void);
-extern int nni_sock_hold(nni_sock **, uint32_t);
+extern int nni_sock_find(nni_sock **, uint32_t);
+extern void nni_sock_hold(nni_sock *);
extern void nni_sock_rele(nni_sock *);
extern int nni_sock_open(nni_sock **, uint16_t);
extern void nni_sock_close(nni_sock *);