RavEngine
Loading...
Searching...
No Matches
SpinLock.hpp
1
#pragma once
2
#include <atomic>
3
4
namespace
RavEngine
{
5
9
class
SpinLock
{
10
std::atomic_flag flag
11
#ifndef _WIN32
12
ATOMIC_FLAG_INIT
13
#endif
14
;
15
public
:
16
inline
void
lock(){
17
while
(flag.test_and_set());
18
}
19
20
inline
void
unlock(){
21
flag.clear();
22
}
23
24
// constructors and operators
25
SpinLock
(){};
26
//SpinLock(SpinLock&& other){}
27
28
// copy-assign or copy-construct a lock does NOT
29
// copy its state. These exist as conveniences for other things.
30
SpinLock
(
const
SpinLock
& other){}
31
inline
void
operator=(
const
SpinLock
& other){}
32
};
33
34
// do not dynamic allocate
35
template
<
typename
T>
36
struct
RAIILock
{
37
T& lock;
38
39
RAIILock
(T& lock) : lock(lock) {
40
lock.lock();
41
}
42
~RAIILock
() {
43
lock.unlock();
44
}
45
};
46
47
}
RavEngine::SpinLock
Definition
SpinLock.hpp:9
RavEngine
Definition
Animation.hpp:6
RavEngine::RAIILock
Definition
SpinLock.hpp:36
RavEngine
include
RavEngine
SpinLock.hpp
Generated by
1.9.8