| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <nn/os/os_MutexTypes.h> |
| 4 | #include <nn/util.h> |
| 5 | |
| 6 | namespace nn::os { |
| 7 | |
| 8 | // todo: figure out where these go |
| 9 | void InitializeMutex(MutexType*, bool, s32); |
| 10 | void FinalizeMutex(MutexType*); |
| 11 | void LockMutex(MutexType*); |
| 12 | bool TryLockMutex(MutexType*); |
| 13 | void UnlockMutex(MutexType*); |
| 14 | bool IsMutexLockedByCurrentThread(const MutexType*); |
| 15 | |
| 16 | class Mutex { |
| 17 | NN_NO_COPY(Mutex); |
| 18 | NN_NO_MOVE(Mutex); |
| 19 | |
| 20 | public: |
| 21 | explicit Mutex(bool recursive) { InitializeMutex(&m_Mutex, recursive, 0); } |
| 22 | |
| 23 | Mutex(bool, int); |
| 24 | ~Mutex(); |
| 25 | |
| 26 | void Lock() { LockMutex(&m_Mutex); } |
| 27 | |
| 28 | bool TryLock(); |
| 29 | void Unlock() { UnlockMutex(&m_Mutex); } |
| 30 | bool IsLockedByCurrentThread() const; |
| 31 | void lock(); |
| 32 | bool try_lock(); |
| 33 | void unlock(); |
| 34 | operator MutexType&(); |
| 35 | operator const MutexType&() const; |
| 36 | MutexType* GetBase(); |
| 37 | |
| 38 | private: |
| 39 | MutexType m_Mutex; |
| 40 | }; |
| 41 | |
| 42 | } // namespace nn::os |