summaryrefslogtreecommitdiff
path: root/Runtime/Threads/SpinlockMutex.h
blob: 63ca9aa6e63ca980f8cdf7fdf0c4642a70d40f51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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