Skip to content

Commit 7ff8929

Browse files
authored
[libc] Update fence to use scoped fence now that it's supported (#119018)
Summary: Adds support for scoped fences now that the NVPTX backend doesn't break on them.
1 parent 6cb339f commit 7ff8929

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

libc/src/__support/CPP/atomic.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,12 @@ 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+
__scoped_atomic_thread_fence(static_cast<int>(mem_ord),
222+
static_cast<int>(mem_scope));
222223
#else
223224
__atomic_thread_fence(static_cast<int>(mem_ord));
224225
#endif

0 commit comments

Comments
 (0)