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
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);