[libc-commits] [libc] d4380fc - [libc] Add `fetch_or` to the atomic interface
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Sat Apr 15 05:43:23 PDT 2023
Author: Joseph Huber
Date: 2023-04-15T07:42:51-05:00
New Revision: d4380fcbb8ea9994f26ea3cd8a59bfa601c302d6
URL: https://github.com/llvm/llvm-project/commit/d4380fcbb8ea9994f26ea3cd8a59bfa601c302d6
DIFF: https://github.com/llvm/llvm-project/commit/d4380fcbb8ea9994f26ea3cd8a59bfa601c302d6.diff
LOG: [libc] Add `fetch_or` to the atomic interface
Summary:
This patch adds `fetch_or`. It is mainly useful for querying and set a
bit's status without using the more expensive `exchange` functions.
Added:
Modified:
libc/src/__support/CPP/atomic.h
Removed:
################################################################################
diff --git a/libc/src/__support/CPP/atomic.h b/libc/src/__support/CPP/atomic.h
index 5514062525cc..495d492a0b7c 100644
--- a/libc/src/__support/CPP/atomic.h
+++ b/libc/src/__support/CPP/atomic.h
@@ -86,6 +86,10 @@ template <typename T> struct Atomic {
return __atomic_fetch_add(&val, increment, int(mem_ord));
}
+ T fetch_or(T mask, MemoryOrder mem_ord = MemoryOrder::SEQ_CST) {
+ return __atomic_fetch_or(&val, mask, int(mem_ord));
+ }
+
T fetch_sub(T decrement, MemoryOrder mem_ord = MemoryOrder::SEQ_CST) {
return __atomic_fetch_sub(&val, decrement, int(mem_ord));
}
More information about the libc-commits
mailing list