mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-09 22:56:35 +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();
|
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. */
|
/* Acquire exclusive access to exception handling logic. */
|
||||||
if (!g_is_locked.exchange(true)) {
|
if (!g_is_locked.Exchange(true)) {
|
||||||
/* Invoke the exception handler impl. */
|
/* Invoke the exception handler impl. */
|
||||||
ExceptionHandlerImpl(lr, sp);
|
ExceptionHandlerImpl(lr, sp);
|
||||||
|
|
||||||
|
|
|
@ -21,35 +21,47 @@ namespace ams::secmon::smc {
|
||||||
|
|
||||||
namespace {
|
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 TryLockSecurityEngine() {
|
||||||
bool value = false;
|
return TryLockSecurityEngineImpl();
|
||||||
return g_is_locked.compare_exchange_strong(value, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnlockSecurityEngine() {
|
void UnlockSecurityEngine() {
|
||||||
g_is_locked = false;
|
return UnlockSecurityEngineImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsSecurityEngineLocked() {
|
bool IsSecurityEngineLocked() {
|
||||||
return g_is_locked;
|
return IsSecurityEngineLockedImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
SmcResult LockSecurityEngineAndInvoke(SmcArguments &args, SmcHandler impl) {
|
SmcResult LockSecurityEngineAndInvoke(SmcArguments &args, SmcHandler impl) {
|
||||||
/* Try to lock the security engine. */
|
/* Try to lock the security engine. */
|
||||||
SMC_R_UNLESS(TryLockSecurityEngine(), Busy);
|
SMC_R_UNLESS(TryLockSecurityEngineImpl(), Busy);
|
||||||
ON_SCOPE_EXIT { UnlockSecurityEngine(); };
|
ON_SCOPE_EXIT { UnlockSecurityEngineImpl(); };
|
||||||
|
|
||||||
return impl(args);
|
return impl(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
SmcResult LockSecurityEngineAndInvokeAsync(SmcArguments &args, SmcHandler impl, GetResultHandler result_handler) {
|
SmcResult LockSecurityEngineAndInvokeAsync(SmcArguments &args, SmcHandler impl, GetResultHandler result_handler) {
|
||||||
/* Try to lock the security engine. */
|
/* Try to lock the security engine. */
|
||||||
SMC_R_UNLESS(TryLockSecurityEngine(), Busy);
|
SMC_R_UNLESS(TryLockSecurityEngineImpl(), Busy);
|
||||||
auto se_guard = SCOPE_GUARD { UnlockSecurityEngine(); };
|
auto se_guard = SCOPE_GUARD { UnlockSecurityEngineImpl(); };
|
||||||
|
|
||||||
/* Try to start an async operation. */
|
/* Try to start an async operation. */
|
||||||
const u64 async_key = BeginAsyncOperation(result_handler);
|
const u64 async_key = BeginAsyncOperation(result_handler);
|
||||||
|
|
Loading…
Reference in a new issue