| 1 | #ifndef SEAD_CRITICAL_SECTION_H_ |
| 2 | #define SEAD_CRITICAL_SECTION_H_ |
| 3 | |
| 4 | #if defined(cafe) |
| 5 | #include <cafe.h> |
| 6 | #elif defined(NNSDK) |
| 7 | #include <nn/os.h> |
| 8 | #endif |
| 9 | |
| 10 | #include <basis/seadTypes.h> |
| 11 | #include <heap/seadDisposer.h> |
| 12 | |
| 13 | namespace sead |
| 14 | { |
| 15 | class Heap; |
| 16 | |
| 17 | class CriticalSection : public IDisposer |
| 18 | { |
| 19 | public: |
| 20 | CriticalSection(); |
| 21 | explicit CriticalSection(Heap* disposer_heap); |
| 22 | CriticalSection(Heap* disposer_heap, HeapNullOption heap_null_option); |
| 23 | ~CriticalSection() override; |
| 24 | |
| 25 | CriticalSection(const CriticalSection&) = delete; |
| 26 | CriticalSection& operator=(const CriticalSection&) = delete; |
| 27 | |
| 28 | void lock(); |
| 29 | bool tryLock(); |
| 30 | void unlock(); |
| 31 | |
| 32 | // For compatibility with the standard Lockable concept. |
| 33 | bool try_lock() { return tryLock(); } |
| 34 | |
| 35 | #if defined(cafe) |
| 36 | OSMutex mCriticalSectionInner; |
| 37 | #elif defined(NNSDK) |
| 38 | nn::os::MutexType mCriticalSectionInner; |
| 39 | #else |
| 40 | #error "Unknown platform" |
| 41 | #endif |
| 42 | }; |
| 43 | |
| 44 | } // namespace sead |
| 45 | |
| 46 | #endif // SEAD_CRITICAL_SECTION_H_ |
| 47 | |