mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-18 08:22:04 +00:00
exo: use the fancy new optimal atomics
This commit is contained in:
parent
d74f364107
commit
c6d7174dd3
2 changed files with 23 additions and 11 deletions
|
@ -22,7 +22,7 @@ namespace ams::secmon {
|
|||
|
||||
constexpr inline uintptr_t PMC = MemoryRegionVirtualDevicePmc.GetAddress();
|
||||
|
||||
constinit std::atomic_bool g_is_locked = false;
|
||||
constinit util::Atomic<bool> g_is_locked{false};
|
||||
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ namespace ams::secmon {
|
|||
}
|
||||
|
||||
/* Acquire exclusive access to exception handling logic. */
|
||||
if (!g_is_locked.exchange(true)) {
|
||||
if (!g_is_locked.Exchange(true)) {
|
||||
/* Invoke the exception handler impl. */
|
||||
ExceptionHandlerImpl(lr, sp);
|
||||
|
||||
|
|
|
@ -21,35 +21,47 @@ namespace ams::secmon::smc {
|
|||
|
||||
namespace {
|
||||
|
||||
constinit std::atomic_bool g_is_locked = false;
|
||||
constinit util::Atomic<bool> g_is_locked{false};
|
||||
|
||||
ALWAYS_INLINE bool TryLockSecurityEngineImpl() {
|
||||
bool value = false;
|
||||
return g_is_locked.CompareExchangeStrong(value, true);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void UnlockSecurityEngineImpl() {
|
||||
g_is_locked = false;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool IsSecurityEngineLockedImpl() {
|
||||
return g_is_locked.Load();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool TryLockSecurityEngine() {
|
||||
bool value = false;
|
||||
return g_is_locked.compare_exchange_strong(value, true);
|
||||
return TryLockSecurityEngineImpl();
|
||||
}
|
||||
|
||||
void UnlockSecurityEngine() {
|
||||
g_is_locked = false;
|
||||
return UnlockSecurityEngineImpl();
|
||||
}
|
||||
|
||||
bool IsSecurityEngineLocked() {
|
||||
return g_is_locked;
|
||||
return IsSecurityEngineLockedImpl();
|
||||
}
|
||||
|
||||
SmcResult LockSecurityEngineAndInvoke(SmcArguments &args, SmcHandler impl) {
|
||||
/* Try to lock the security engine. */
|
||||
SMC_R_UNLESS(TryLockSecurityEngine(), Busy);
|
||||
ON_SCOPE_EXIT { UnlockSecurityEngine(); };
|
||||
SMC_R_UNLESS(TryLockSecurityEngineImpl(), Busy);
|
||||
ON_SCOPE_EXIT { UnlockSecurityEngineImpl(); };
|
||||
|
||||
return impl(args);
|
||||
}
|
||||
|
||||
SmcResult LockSecurityEngineAndInvokeAsync(SmcArguments &args, SmcHandler impl, GetResultHandler result_handler) {
|
||||
/* Try to lock the security engine. */
|
||||
SMC_R_UNLESS(TryLockSecurityEngine(), Busy);
|
||||
auto se_guard = SCOPE_GUARD { UnlockSecurityEngine(); };
|
||||
SMC_R_UNLESS(TryLockSecurityEngineImpl(), Busy);
|
||||
auto se_guard = SCOPE_GUARD { UnlockSecurityEngineImpl(); };
|
||||
|
||||
/* Try to start an async operation. */
|
||||
const u64 async_key = BeginAsyncOperation(result_handler);
|
||||
|
|
Loading…
Reference in a new issue