From ee45cbf4498a3c1d1868469bdb0c767d66c278e4 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 22 Dec 2016 20:52:45 -0800 Subject: Endpoint dialer implemented. --- src/platform/posix/posix_thread.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/platform/posix/posix_thread.c') 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 #include #include +#include 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 -- cgit v1.2.3-70-g09d2