Plasma Engine  2.0
Loading...
Searching...
No Matches
Mutex.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Threading/Implementation/ThreadingDeclarations.h>
5
12class PL_FOUNDATION_DLL plMutex
13{
14 PL_DISALLOW_COPY_AND_ASSIGN(plMutex);
15
16public:
17 plMutex();
18 ~plMutex();
19
21 void Lock();
22
26 plResult TryLock();
27
29 void Unlock();
30
35 PL_ALWAYS_INLINE bool IsLocked() const { return m_iLockCount > 0; }
36
37 plMutexHandle& GetMutexHandle() { return m_hHandle; }
38
39private:
40 plMutexHandle m_hHandle;
41 plInt32 m_iLockCount = 0;
42};
43
48class PL_FOUNDATION_DLL plNoMutex
49{
50public:
52 PL_ALWAYS_INLINE void Lock() {}
53
55 PL_ALWAYS_INLINE plResult TryLock() { return PL_SUCCESS; }
56
58 PL_ALWAYS_INLINE void Unlock() {}
59
60 PL_ALWAYS_INLINE bool IsLocked() const { return false; }
61};
62
63#if PL_ENABLED(PL_PLATFORM_WINDOWS)
64# include <Foundation/Threading/Implementation/Win/Mutex_win.h>
65#elif PL_ENABLED(PL_PLATFORM_OSX) || PL_ENABLED(PL_PLATFORM_LINUX) || PL_ENABLED(PL_PLATFORM_ANDROID)
66# include <Foundation/Threading/Implementation/Posix/Mutex_posix.h>
67#else
68# error "Mutex is not implemented on current platform"
69#endif
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
PL_ALWAYS_INLINE bool IsLocked() const
Returns true, if the mutex is currently acquired. Can be used to assert that a lock was entered.
Definition Mutex.h:35
A dummy mutex that does no locking.
Definition Mutex.h:49
PL_ALWAYS_INLINE void Lock()
Implements the 'Acquire' interface function, but does nothing.
Definition Mutex.h:52
PL_ALWAYS_INLINE plResult TryLock()
Implements the 'TryLock' interface function, but does nothing.
Definition Mutex.h:55
PL_ALWAYS_INLINE void Unlock()
Implements the 'Release' interface function, but does nothing.
Definition Mutex.h:58
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54