]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Change the _LOCK macro on Windows and the variable initialization to be more VC compa...
authorOndřej Surý <ondrej@sury.org>
Wed, 30 May 2018 05:03:35 +0000 (07:03 +0200)
committerOndřej Surý <ondrej@sury.org>
Wed, 30 May 2018 05:28:19 +0000 (07:28 +0200)
lib/isc/random.c
lib/isc/xoshiro128starstar.c

index f74a08665b9404e933e5643c9978f7021a87380d..9e78878170af21eb32ca02f78b8dc90dc2a7fa77 100644 (file)
@@ -92,15 +92,15 @@ isc_random32(void) {
 
 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
index a737bfd91c83d83a85629058003db2154bb87b56..e2466dd54cb0538be6b1195ea8cb3b198bb63d4a 100644 (file)
@@ -44,14 +44,17 @@ static volatile HANDLE _mutex = NULL;
  * 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)
 
@@ -75,11 +78,12 @@ static isc_uint32_t seed[4];
 
 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];