summaryrefslogtreecommitdiff
path: root/Runtime/Threads/SpinlockMutex.h
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Threads/SpinlockMutex.h')
-rw-r--r--Runtime/Threads/SpinlockMutex.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/Runtime/Threads/SpinlockMutex.h b/Runtime/Threads/SpinlockMutex.h
new file mode 100644
index 0000000..63ca9aa
--- /dev/null
+++ b/Runtime/Threads/SpinlockMutex.h
@@ -0,0 +1,63 @@
+#ifndef __SPINLOCK_MUTEX_H
+#define __SPINLOCK_MUTEX_H
+
+#if UNITY_OSX
+
+#include <libkern/OSAtomic.h>
+
+class SpinlockMutex : public NonCopyable
+{
+public:
+
+ class AutoLock
+ {
+ public:
+ AutoLock( SpinlockMutex& mutex )
+ : m_Mutex(&mutex)
+ {
+ mutex.Lock();
+ }
+
+ ~AutoLock()
+ {
+ m_Mutex->Unlock();
+ }
+
+ private:
+ AutoLock(const AutoLock&);
+ AutoLock& operator=(const AutoLock&);
+
+ private:
+ SpinlockMutex* m_Mutex;
+ };
+
+ SpinlockMutex()
+ {
+ m_SpinLock = OS_SPINLOCK_INIT;
+ }
+
+ ~SpinlockMutex()
+ {}
+
+ void Lock()
+ {
+ OSSpinLockLock(&m_SpinLock);
+ }
+
+ void Unlock()
+ {
+ OSSpinLockUnlock(&m_SpinLock);
+ }
+
+private:
+
+ volatile OSSpinLock m_SpinLock;
+};
+
+#else
+
+typedef Mutex SpinlockMutex;
+
+#endif
+
+#endif \ No newline at end of file