void
isc_random_buf(void *buf, size_t buflen) {
+ int i;
+ isc_uint32_t r;
+
REQUIRE(buf);
REQUIRE(buflen > 0);
RUNTIME_CHECK(isc_once_do(&isc_random_once,
isc_random_initialize) == ISC_R_SUCCESS);
- int i;
- isc_uint32_t r;
-
for (i = 0; i + sizeof(r) <= buflen; i += sizeof(r)) {
r = next();
memmove((uint8_t *)buf + i, &r, sizeof(r)); /* Buffers cannot
* will attempt to allocate a mutex and compare-and-swap it into place as the
* global mutex. On failure to swap in the global mutex, the mutex is closed.
*/
-#define _LOCK() { \
- if (!_mutex) { \
- HANDLE p = CreateMutex(NULL, FALSE, NULL); \
- if (InterlockedCompareExchangePointer((void **)&_mutex, (void *)p, NULL)) \
- CloseHandle(p); \
- } \
- WaitForSingleObject(_mutex, INFINITE); \
-}
+#define _LOCK() \
+ do { \
+ if (!_mutex) { \
+ HANDLE p = CreateMutex(NULL, FALSE, NULL); \
+ if (InterlockedCompareExchangePointer \
+ ((void **)&_mutex, (void *)p, NULL)) { \
+ CloseHandle(p); \
+ } \
+ } \
+ WaitForSingleObject(_mutex, INFINITE); \
+ } while (0)
#define _UNLOCK() ReleaseMutex(_mutex)
static inline isc_uint32_t
next(void) {
- _LOCK();
+ isc_uint32_t result_starstar, t;
- const isc_uint32_t result_starstar = rotl(seed[0] * 5, 7) * 9;
+ _LOCK();
- const isc_uint32_t t = seed[1] << 9;
+ result_starstar = rotl(seed[0] * 5, 7) * 9;
+ t = seed[1] << 9;
seed[2] ^= seed[0];
seed[3] ^= seed[1];