Plasma Engine  2.0
Loading...
Searching...
No Matches
Mutex_posix.h
1
2PL_ALWAYS_INLINE plMutex::plMutex()
3{
4 pthread_mutexattr_t mutexAttributes;
5 pthread_mutexattr_init(&mutexAttributes);
6 pthread_mutexattr_settype(&mutexAttributes, PTHREAD_MUTEX_RECURSIVE);
7
8 pthread_mutex_init(&m_hHandle, &mutexAttributes);
9
10 pthread_mutexattr_destroy(&mutexAttributes);
11}
12
13PL_ALWAYS_INLINE plMutex::~plMutex()
14{
15 pthread_mutex_destroy(&m_hHandle);
16}
17
18PL_ALWAYS_INLINE void plMutex::Lock()
19{
20 pthread_mutex_lock(&m_hHandle);
21 ++m_iLockCount;
22}
23
24PL_ALWAYS_INLINE plResult plMutex::TryLock()
25{
26 if (pthread_mutex_trylock(&m_hHandle) == 0)
27 {
28 ++m_iLockCount;
29 return PL_SUCCESS;
30 }
31
32 return PL_FAILURE;
33}
34PL_ALWAYS_INLINE void plMutex::Unlock()
35{
36 --m_iLockCount;
37 pthread_mutex_unlock(&m_hHandle);
38}
void Unlock()
Releases a lock that has been previously acquired.
Definition Mutex_posix.h:34
plResult TryLock()
Attempts to acquire an exclusive lock for this mutex object. Returns true on success.
Definition Mutex_posix.h:24
void Lock()
Acquires an exclusive lock for this mutex object.
Definition Mutex_posix.h:18
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54