From a2f314548c7b9117fc15537c0f9fc32147afc5e2 Mon Sep 17 00:00:00 2001 From: Nitr4m12 <67806925+Nitr4m12@users.noreply.github.com> Date: Wed, 2 Sep 2026 14:28:07 -0400 Subject: [PATCH] os: Implement `os::Mutex` --- include/nn/os/os_Mutex.h | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/include/nn/os/os_Mutex.h b/include/nn/os/os_Mutex.h index 6656ce46..d091ca66 100644 --- a/include/nn/os/os_Mutex.h +++ b/include/nn/os/os_Mutex.h @@ -6,7 +6,7 @@ namespace nn::os { // todo: figure out where these go -void InitializeMutex(MutexType*, bool, s32); +void InitializeMutex(MutexType*, bool recursive, s32 lockLevel); void FinalizeMutex(MutexType*); void LockMutex(MutexType*); bool TryLockMutex(MutexType*); @@ -20,20 +20,29 @@ class Mutex { public: explicit Mutex(bool recursive) { InitializeMutex(&m_Mutex, recursive, 0); } - Mutex(bool, int); - ~Mutex(); + Mutex(bool recursive, s32 lockLevel) { InitializeMutex(&m_Mutex, recursive, lockLevel); }; + + ~Mutex() { FinalizeMutex(&m_Mutex); } void Lock() { LockMutex(&m_Mutex); } - bool TryLock(); + bool TryLock() { return TryLockMutex(&m_Mutex); } + void Unlock() { UnlockMutex(&m_Mutex); } - bool IsLockedByCurrentThread() const; - void lock(); - bool try_lock(); - void unlock(); - operator MutexType&(); - operator const MutexType&() const; - MutexType* GetBase(); + + bool IsLockedByCurrentThread() const { return IsMutexLockedByCurrentThread(&m_Mutex); }; + + void lock() { Lock(); } + + bool try_lock() { return TryLock(); } + + void unlock() { Unlock(); } + + operator MutexType&() { return m_Mutex; } + + operator const MutexType&() const { return m_Mutex; } + + MutexType* GetBase() { return &m_Mutex; } private: MutexType m_Mutex;