1#ifndef YAZE_APP_PLATFORM_WASM_WASM_ASYNC_GUARD_H_
2#define YAZE_APP_PLATFORM_WASM_WASM_ASYNC_GUARD_H_
35 static bool TryAcquire() {
36 bool expected =
false;
37 return in_async_op_.compare_exchange_strong(expected,
true);
43 static void Release() { in_async_op_.store(
false); }
49 static bool IsInProgress() {
return in_async_op_.load(); }
60 ScopedGuard() : acquired_(TryAcquire()) {
64 "[WasmAsyncGuard] Async operation already in progress, "
65 "request will be queued by JS async queue");
76 ScopedGuard(
const ScopedGuard&) =
delete;
77 ScopedGuard& operator=(
const ScopedGuard&) =
delete;
83 bool acquired()
const {
return acquired_; }
90 static std::atomic<bool> in_async_op_;