Pothos  0.4.0-gd11861cd
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
SpinLock.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 #include <Pothos/Config.hpp>
13 #include <atomic>
14 
15 namespace Pothos {
16 namespace Util {
17 
27 {
28 public:
29 
31  SpinLock(void)
32  {
33  this->unlock();
34  }
35 
37  void lock(void)
38  {
39  while (_lock.test_and_set(std::memory_order_acquire)){}
40  }
41 
43  void unlock(void)
44  {
45  _lock.clear(std::memory_order_release);
46  }
47 
48 private:
49  std::atomic_flag _lock;
50 };
51 
52 } //namespace Util
53 } //namespace Pothos
#define POTHOS_API
Definition: Config.hpp:41
void lock(void)
Lock the spin lock, block if already locked.
Definition: SpinLock.hpp:37
Definition: SpinLock.hpp:26
SpinLock(void)
Create a new unlocked spin lock.
Definition: SpinLock.hpp:31
void unlock(void)
Unlock the spin lock (should be already locked)
Definition: SpinLock.hpp:43