Skip to content

Commit

Permalink
Switch to newer, explicit atomic API (dotnet/corefx#37456)
Browse files Browse the repository at this point in the history
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 dotnet/corefx@bd27863
  • Loading branch information
roji authored and ViktorHofer committed May 6, 2019
1 parent e3c91c7 commit 4c5b898
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libraries/Native/Unix/System.Native/pal_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4c5b898

Please sign in to comment.