| 1 | #include "thread/seadCriticalSection.h" |
|---|---|
| 2 | |
| 3 | namespace sead |
| 4 | { |
| 5 | CriticalSection::CriticalSection() : IDisposer() |
| 6 | { |
| 7 | nn::os::InitializeMutex(&mCriticalSectionInner, true, 0); |
| 8 | } |
| 9 | |
| 10 | CriticalSection::CriticalSection(Heap* disposer_heap) |
| 11 | : IDisposer(disposer_heap, HeapNullOption::UseSpecifiedOrContainHeap) |
| 12 | { |
| 13 | nn::os::InitializeMutex(&mCriticalSectionInner, true, 0); |
| 14 | } |
| 15 | |
| 16 | CriticalSection::CriticalSection(Heap* disposer_heap, HeapNullOption heap_null_option) |
| 17 | : IDisposer(disposer_heap, heap_null_option) |
| 18 | { |
| 19 | nn::os::InitializeMutex(&mCriticalSectionInner, true, 0); |
| 20 | } |
| 21 | |
| 22 | CriticalSection::~CriticalSection() |
| 23 | { |
| 24 | nn::os::FinalizeMutex(&mCriticalSectionInner); |
| 25 | } |
| 26 | |
| 27 | void CriticalSection::lock() |
| 28 | { |
| 29 | nn::os::LockMutex(&mCriticalSectionInner); |
| 30 | } |
| 31 | |
| 32 | bool CriticalSection::tryLock() |
| 33 | { |
| 34 | return nn::os::TryLockMutex(&mCriticalSectionInner); |
| 35 | } |
| 36 | |
| 37 | void CriticalSection::unlock() |
| 38 | { |
| 39 | nn::os::UnlockMutex(&mCriticalSectionInner); |
| 40 | } |
| 41 | } // namespace sead |
| 42 |