aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix/posix_thread.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2016-12-22 20:52:45 -0800
committerGarrett D'Amore <garrett@damore.org>2016-12-22 20:52:45 -0800
commitee45cbf4498a3c1d1868469bdb0c767d66c278e4 (patch)
treeb9116256f12a54c90f92bf5cf215f3d4c8152126 /src/platform/posix/posix_thread.c
parent718de1828cc5b5256511c5b723360d499ae21c8f (diff)
downloadnng-ee45cbf4498a3c1d1868469bdb0c767d66c278e4.tar.gz
nng-ee45cbf4498a3c1d1868469bdb0c767d66c278e4.tar.bz2
nng-ee45cbf4498a3c1d1868469bdb0c767d66c278e4.zip
Endpoint dialer implemented.
Diffstat (limited to 'src/platform/posix/posix_thread.c')
-rw-r--r--src/platform/posix/posix_thread.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c
index 80f3b96f..24f97b81 100644
--- a/src/platform/posix/posix_thread.c
+++ b/src/platform/posix/posix_thread.c
@@ -16,6 +16,7 @@
#include <pthread.h>
#include <time.h>
#include <string.h>
+#include <stdlib.h>
struct nni_thread {
pthread_t tid;
@@ -26,6 +27,17 @@ struct nni_thread {
static pthread_mutex_t nni_plat_lock = PTHREAD_MUTEX_INITIALIZER;
static int nni_plat_inited = 0;
static int nni_plat_forked = 0;
+static int nni_plat_next = 0;
+
+uint32_t
+nni_plat_nextid(void)
+{
+ uint32_t id;
+ pthread_mutex_lock(&nni_plat_lock);
+ id = nni_plat_next++;
+ pthread_mutex_unlock(&nni_plat_lock);
+ return (id);
+}
static void *
nni_thrfunc(void *arg)
@@ -118,6 +130,20 @@ nni_plat_init(int (*helper)(void))
return (NNG_ENOMEM);
}
+ // Generate a starting ID (used for Pipe IDs)
+#ifdef NNG_HAVE_ARC4RANDOM
+ nni_plat_next = arc4random();
+#else
+ while (nni_plat_next == 0) {
+ uint16_t xsub[3];
+ nni_time now = nni_clock();
+
+ xsub[0] = (uint16_t)now;
+ xsub[1] = (uint16_t)(now >> 16);
+ xsub[2] = (uint16_t)(now >> 24);
+ nni_plat_next = nrand48(xsub);
+ }
+#endif
if (pthread_atfork(NULL, NULL, nni_atfork_child) != 0) {
pthread_mutex_unlock(&nni_plat_lock);
@@ -144,5 +170,4 @@ nni_plat_fini(void)
pthread_mutex_unlock(&nni_plat_lock);
}
-
#endif