MutexImpl.h
1.4 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#if IL2CPP_THREADS_PTHREAD && !RUNTIME_TINY
#include "os/ErrorCodes.h"
#include "os/WaitStatus.h"
#include "PosixWaitObject.h"
#include <pthread.h>
namespace il2cpp
{
namespace os
{
class Thread;
class MutexImpl : public posix::PosixWaitObject
{
public:
MutexImpl();
void Lock(bool interruptible);
bool TryLock(uint32_t milliseconds, bool interruptible);
void Unlock();
private:
/// Thread that currently owns the object. Used for recursion checks.
Thread* m_OwningThread;
/// Number of recursive locks on the owning thread.
uint32_t m_RecursionCount;
};
class FastMutexImpl
{
public:
FastMutexImpl()
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&m_Mutex, &attr);
pthread_mutexattr_destroy(&attr);
}
~FastMutexImpl()
{
pthread_mutex_destroy(&m_Mutex);
}
void Lock()
{
pthread_mutex_lock(&m_Mutex);
}
void Unlock()
{
pthread_mutex_unlock(&m_Mutex);
}
pthread_mutex_t* GetOSHandle()
{
return &m_Mutex;
}
private:
pthread_mutex_t m_Mutex;
};
}
}
#endif