ReaderWriterLock.h
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include "utils/NonCopyable.h"
namespace il2cpp
{
namespace os
{
class ReaderWriterLockImpl;
class ReaderWriterLock
{
public:
ReaderWriterLock();
~ReaderWriterLock();
void LockExclusive();
void LockShared();
void ReleaseExclusive();
void ReleaseShared();
ReaderWriterLockImpl* GetImpl();
private:
ReaderWriterLockImpl* m_Impl;
};
struct ReaderWriterAutoLock : public il2cpp::utils::NonCopyable
{
ReaderWriterAutoLock(ReaderWriterLock* lock, bool exclusive = false)
: m_Lock(lock), m_Exclusive(exclusive)
{
if (m_Exclusive)
m_Lock->LockExclusive();
else
m_Lock->LockShared();
}
~ReaderWriterAutoLock()
{
if (m_Exclusive)
m_Lock->ReleaseExclusive();
else
m_Lock->ReleaseShared();
}
private:
ReaderWriterLock* m_Lock;
bool m_Exclusive;
};
}
}