summaryrefslogtreecommitdiff
path: root/Runtime/Threads/Mutex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Threads/Mutex.cpp')
-rw-r--r--Runtime/Threads/Mutex.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/Runtime/Threads/Mutex.cpp b/Runtime/Threads/Mutex.cpp
new file mode 100644
index 0000000..9ca9991
--- /dev/null
+++ b/Runtime/Threads/Mutex.cpp
@@ -0,0 +1,70 @@
+#include "UnityPrefix.h"
+
+#if SUPPORT_THREADS
+
+#include "Mutex.h"
+
+#ifndef THREAD_LOCK_DEBUG
+#define THREAD_LOCK_DEBUG 0
+#endif
+
+Mutex::Mutex()
+{
+}
+
+Mutex::~Mutex ()
+{
+}
+
+bool Mutex::IsLocked()
+{
+ if(m_Mutex.TryLock())
+ {
+ Unlock();
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+}
+
+void Mutex::BlockUntilUnlocked()
+{
+ Lock();
+ Unlock();
+}
+
+void Mutex::Lock()
+{
+#if THREAD_LOCK_DEBUG
+ m_PerThreadLockDepth.SetIntValue(m_PerThreadLockDepth.GetIntValue() + 1);
+#endif
+ m_Mutex.Lock();
+}
+
+void Mutex::Unlock()
+{
+#if THREAD_LOCK_DEBUG
+ AssertIf(m_PerThreadLockDepth.GetIntValue() == 0);
+ m_PerThreadLockDepth.SetIntValue(m_PerThreadLockDepth.GetIntValue() - 1);
+#endif
+ m_Mutex.Unlock();
+}
+
+bool Mutex::TryLock()
+{
+#if THREAD_LOCK_DEBUG
+ if (m_Mutex.TryLock())
+ {
+ m_PerThreadLockDepth.SetIntValue(m_PerThreadLockDepth.GetIntValue() + 1);
+ return true;
+ }
+ else
+ return false;
+#else
+ return m_Mutex.TryLock();
+#endif
+}
+
+#endif // SUPPORT_THREADS ; has dummy mutex implemented in headerfile