[libc-commits] [libc] [libc][cpp] add `atomic_signal_fence` (PR #82138)
via libc-commits
libc-commits at lists.llvm.org
Sat Feb 17 15:34:06 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Schrodinger ZHU Yifan (SchrodingerZhu)
<details>
<summary>Changes</summary>
Add `atomic_signal_fence`. This will be useful in https://gustedt.gitlabpages.inria.fr/c23-library/#memset_explicit.
---
Full diff: https://github.com/llvm/llvm-project/pull/82138.diff
1 Files Affected:
- (modified) libc/src/__support/CPP/atomic.h (+15)
``````````diff
diff --git a/libc/src/__support/CPP/atomic.h b/libc/src/__support/CPP/atomic.h
index 1c4478dfeab6de..61e2742661f21a 100644
--- a/libc/src/__support/CPP/atomic.h
+++ b/libc/src/__support/CPP/atomic.h
@@ -161,6 +161,21 @@ LIBC_INLINE void atomic_thread_fence(MemoryOrder mem_ord) {
#endif
}
+// Establishes memory synchronization ordering of non-atomic and relaxed atomic
+// accesses, as instructed by order, between a thread and a signal handler
+// executed on the same thread. This is equivalent to atomic_thread_fence,
+// except no instructions for memory ordering are issued. Only reordering of
+// the instructions by the compiler is suppressed as order instructs.
+LIBC_INLINE void atomic_signal_fence(MemoryOrder mem_ord) {
+#if __has_builtin(__atomic_signal_fence)
+ __atomic_signal_fence(int(mem_ord));
+#else
+ // if the builtin is not ready, use asm as a full compiler barrier.
+ (void)mem_ord;
+ asm volatile("" ::: "memory");
+#endif
+}
+
} // namespace cpp
} // namespace LIBC_NAMESPACE
``````````
</details>
https://github.com/llvm/llvm-project/pull/82138
More information about the libc-commits
mailing list