From 3bccb7f358e27f932c951a55bc17aa113bfae5f0 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Mon, 10 Jul 2017 21:07:12 +0300 Subject: Introducing thread-safe nxt_random(). --- src/nxt_random.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/nxt_random.c') diff --git a/src/nxt_random.c b/src/nxt_random.c index 9af40079..ea73ae18 100644 --- a/src/nxt_random.c +++ b/src/nxt_random.c @@ -8,8 +8,6 @@ #include -#if !(NXT_HAVE_ARC4RANDOM) - /* * The pseudorandom generator based on OpenBSD arc4random. Although it is * usually stated that arc4random uses RC4 pseudorandom generation algorithm @@ -56,7 +54,7 @@ nxt_random_stir(nxt_random_t *r) ssize_t n; struct timeval tv; union { - uint32_t value[3]; + uint32_t value[4]; u_char bytes[NXT_RANDOM_KEY_SIZE]; } key; @@ -87,6 +85,7 @@ nxt_random_stir(nxt_random_t *r) key.value[0] ^= tv.tv_usec; key.value[1] ^= tv.tv_sec; key.value[2] ^= nxt_pid; + key.value[3] ^= nxt_thread_tid(NULL); } nxt_random_add(r, key.bytes, NXT_RANDOM_KEY_SIZE); @@ -202,5 +201,3 @@ nxt_random_unit_test(nxt_thread_t *thr) } #endif - -#endif -- cgit