Switch to newer, explicit atomic API (dotnet/corefx#37456)
authorShay Rojansky <roji@roji.org>
Mon, 6 May 2019 07:58:49 +0000 (00:58 -0700)
committerViktor Hofer <viktor.hofer@microsoft.com>
Mon, 6 May 2019 07:58:48 +0000 (09:58 +0200)
Starting with clang 8, the older __sync atomic functions produce a
warning for implicit strong memory barriers. This switches to the
newer __atomic API where memory ordering is explicitly specified.

Fixes dotnet/corefx#37174

Commit migrated from https://github.com/dotnet/corefx/commit/bd278630dd08914ef521e62658afb69845c5b93a

src/libraries/Native/Unix/System.Native/pal_random.c

index 8a267a3..e085199 100644 (file)
@@ -51,7 +51,8 @@ void SystemNative_GetNonCryptographicallySecureRandomBytes(uint8_t* buffer, int3
 
             if (fd != -1)
             {
-                if (!__sync_bool_compare_and_swap(&rand_des, -1, fd))
+                int expected = -1;
+                if (!__atomic_compare_exchange_n(&rand_des, &expected, fd, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
                 {
                     // Another thread has already set the rand_des
                     close(fd);