Skip to content

Commit

Permalink
[libc] Add fetch_or to the atomic interface
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhuber6 committed Apr 15, 2023
1 parent fa3de2e commit d4380fc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libc/src/__support/CPP/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit d4380fc

Please sign in to comment.