aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/init.c10
-rw-r--r--src/core/pipe.c47
-rw-r--r--src/core/pipe.h3
3 files changed, 60 insertions, 0 deletions
diff --git a/src/core/init.c b/src/core/init.c
index 7b3b4433..3339b532 100644
--- a/src/core/init.c
+++ b/src/core/init.c
@@ -47,7 +47,16 @@ nni_init_helper(void)
nni_taskq_sys_fini();
return (rv);
}
+ if ((rv = nni_pipe_sys_init()) != 0) {
+ nni_ep_sys_fini();
+ nni_sock_sys_fini();
+ nni_random_sys_fini();
+ nni_timer_sys_fini();
+ nni_taskq_sys_fini();
+ return (rv);
+ }
if ((rv = nni_mtx_init(&nni_idlock_x)) != 0) {
+ nni_pipe_sys_fini();
nni_ep_sys_fini();
nni_sock_sys_fini();
nni_random_sys_fini();
@@ -57,6 +66,7 @@ nni_init_helper(void)
}
if ((rv = nni_idhash_init(&nni_pipes_x)) != 0) {
nni_mtx_fini(&nni_idlock_x);
+ nni_pipe_sys_fini();
nni_ep_sys_fini();
nni_sock_sys_fini();
nni_random_sys_fini();
diff --git a/src/core/pipe.c b/src/core/pipe.c
index bc77cd2d..ce33222d 100644
--- a/src/core/pipe.c
+++ b/src/core/pipe.c
@@ -14,6 +14,53 @@
// Operations on pipes (to the transport) are generally blocking operations,
// performed in the context of the protocol.
+static nni_objhash *nni_allpipes;
+
+static void *
+nni_pipe_ctor(uint32_t id)
+{
+ nni_pipe *p;
+
+ if ((p = NNI_ALLOC_STRUCT(p)) == NULL) {
+ return (NULL);
+ }
+ p->p_id = id;
+ return (p);
+}
+
+
+static void
+nni_pipe_dtor(void *ptr)
+{
+ nni_pipe *p = ptr;
+
+ NNI_FREE_STRUCT(p);
+}
+
+
+int
+nni_pipe_sys_init(void)
+{
+ int rv;
+
+ rv = nni_objhash_init(&nni_allpipes, nni_pipe_ctor, nni_pipe_dtor);
+
+ if (rv != 0) {
+ return (rv);
+ }
+
+ return (0);
+}
+
+
+void
+nni_pipe_sys_fini(void)
+{
+ nni_objhash_fini(nni_allpipes);
+ nni_allpipes = NULL;
+}
+
+
// nni_pipe_id returns the 32-bit pipe id, which can be used in backtraces.
uint32_t
nni_pipe_id(nni_pipe *p)
diff --git a/src/core/pipe.h b/src/core/pipe.h
index 912c70bd..e9ce89b3 100644
--- a/src/core/pipe.h
+++ b/src/core/pipe.h
@@ -32,6 +32,9 @@ struct nni_pipe {
int p_refcnt;
};
+extern int nni_pipe_sys_init(void);
+extern void nni_pipe_sys_fini(void);
+
// AIO
extern int nni_pipe_aio_recv(nni_pipe *, nni_aio *);
extern int nni_pipe_aio_send(nni_pipe *, nni_aio *);