From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Threads/SpinlockMutex.h | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Runtime/Threads/SpinlockMutex.h (limited to 'Runtime/Threads/SpinlockMutex.h') 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 + +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 -- cgit v1.1-26-g67d0