Skip to content

Commit 7d7cf74

Browse files
committed
[libc] Update fence to use scoped fence now that it's supported
Summary: Adds support for scoped fences now that the NVPTX backend doesn't break on them.
1 parent 3c83054 commit 7d7cf74

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

libc/src/__support/CPP/atomic.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,14 @@ template <typename T> struct Atomic {
214214
};
215215

216216
// Issue a thread fence with the given memory ordering.
217-
LIBC_INLINE void atomic_thread_fence([[maybe_unused]] MemoryOrder mem_ord) {
218-
// The NVPTX backend currently does not support atomic thread fences so we use a
219-
// full system fence instead.
220-
#ifdef LIBC_TARGET_ARCH_IS_NVPTX
221-
__nvvm_membar_sys();
217+
LIBC_INLINE void atomic_thread_fence(
218+
MemoryOrder mem_ord,
219+
[[maybe_unused]] MemoryScope mem_scope = MemoryScope::DEVICE) {
220+
#if __has_builtin(__scoped_atomic_thread_fence)
221+
return __scoped_atomic_thread_fence(static_cast<int>(mem_ord),
222+
static_cast<int>(mem_scope));
222223
#else
223-
__atomic_thread_fence(static_cast<int>(mem_ord));
224+
return __atomic_thread_fence(static_cast<int>(mem_ord));
224225
#endif
225226
}
226227

0 commit comments

Comments
 (0)