Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Leo-Smith committed Dec 18, 2024
1 parent 3c7c1d1 commit a0cdc19
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/backends/fallback/fallback_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
namespace luisa::compute::fallback {

void FallbackEvent::signal(uint64_t fence_value) noexcept {
#if defined(__has_builtin) && __has_builtin(__c11_atomic_fetch_max)
using A = _Atomic(uint64_t);
auto p = reinterpret_cast<A *>(&_fence_value);
__c11_atomic_fetch_max(p, fence_value, __ATOMIC_RELEASE);
#else
// use a CAS loop to ensure the fence value is monotonically increasing
auto current = _fence_value.load(std::memory_order_acquire);
while (current < fence_value) {
if (_fence_value.compare_exchange_weak(current, fence_value, std::memory_order_release, std::memory_order_acquire)) {
break;
}
}
#endif
}

void FallbackEvent::wait(uint64_t fence_value) const noexcept {
Expand Down

0 comments on commit a0cdc19

Please sign in to comment.