YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
spinlock.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <yaclib_std/atomic>
4
5namespace yaclib::detail {
6
7template <typename T>
8class Spinlock {
9 public:
10 void lock() noexcept {
11 while (_state.exchange(1, std::memory_order_acquire) != 0) {
12 do {
13 // TODO(MBkkt) pause, yield, sleep
14 } while (_state.load(std::memory_order_relaxed) != 0);
15 }
16 }
17
19 _state.store(0, std::memory_order_release);
20 }
21
22 private:
23 yaclib_std::atomic<T> _state = 0;
24};
25
26} // namespace yaclib::detail
void lock() noexcept
Definition spinlock.hpp:10
void unlock() noexcept
Definition spinlock.hpp:18
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25