diff options
Diffstat (limited to 'src/core/global.c')
-rw-r--r-- | src/core/global.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/core/global.c b/src/core/global.c index 9fc55ea..6fbf003 100644 --- a/src/core/global.c +++ b/src/core/global.c @@ -168,6 +168,7 @@ struct nn_global { int print_errors; + int inited; nn_mutex_t lock; nn_condvar_t cond; }; @@ -306,6 +307,10 @@ void nn_term (void) { int i; + if (!self.inited) { + return; + } + nn_mutex_lock (&self.lock); self.flags |= NN_CTX_FLAG_TERMING; nn_mutex_unlock (&self.lock); @@ -323,8 +328,18 @@ void nn_term (void) nn_mutex_unlock (&self.lock); } +static void nn_lib_init(void) +{ + /* This function is executed once to initialize global locks. */ + nn_mutex_init (&self.lock); + nn_condvar_init (&self.cond); + self.inited = 1; +} + void nn_init (void) { + nn_do_once (&once, nn_lib_init); + nn_mutex_lock (&self.lock); /* Wait for any in progress term to complete. */ while (self.flags & NN_CTX_FLAG_TERMING) { @@ -454,13 +469,6 @@ int nn_global_create_socket (int domain, int protocol) return -EINVAL; } -static void nn_lib_init(void) -{ - /* This function is executed once to initialize global locks. */ - nn_mutex_init (&self.lock); - nn_condvar_init (&self.cond); -} - int nn_socket (int domain, int protocol) { int rc; |