1#pragma once
2
3#include <nn/os/os_MutexTypes.h>
4#include <nn/util.h>
5
6namespace nn::os {
7
8// todo: figure out where these go
9void InitializeMutex(MutexType*, bool, s32);
10void FinalizeMutex(MutexType*);
11void LockMutex(MutexType*);
12bool TryLockMutex(MutexType*);
13void UnlockMutex(MutexType*);
14bool IsMutexLockedByCurrentThread(const MutexType*);
15
16class Mutex {
17 NN_NO_COPY(Mutex);
18 NN_NO_MOVE(Mutex);
19
20public:
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
38private:
39 MutexType m_Mutex;
40};
41
42} // namespace nn::os