diff options
author | Igor Sysoev <igor@sysoev.ru> | 2017-07-10 21:07:12 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2017-07-10 21:07:12 +0300 |
commit | 3bccb7f358e27f932c951a55bc17aa113bfae5f0 (patch) | |
tree | 78fc9f0fc0b20c7df284208db901eacc7dd6b6a8 /src/nxt_random.c | |
parent | dc874cd22ef7ec72fc6e5927b1695d4a12536625 (diff) | |
download | unit-3bccb7f358e27f932c951a55bc17aa113bfae5f0.tar.gz unit-3bccb7f358e27f932c951a55bc17aa113bfae5f0.tar.bz2 |
Introducing thread-safe nxt_random().
Diffstat (limited to '')
-rw-r--r-- | src/nxt_random.c | 7 |
1 files changed, 2 insertions, 5 deletions
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 <nxt_main.h> -#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 |