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
5
namespace
yaclib::detail
{
6
7
template
<
typename
T>
8
class
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
18
void
unlock
()
noexcept
{
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
yaclib::detail::Spinlock
Definition
spinlock.hpp:8
yaclib::detail::Spinlock::lock
void lock() noexcept
Definition
spinlock.hpp:10
yaclib::detail::Spinlock::unlock
void unlock() noexcept
Definition
spinlock.hpp:18
yaclib::detail
Definition
base_core.hpp:18
yaclib::MakeContract
Contract< V, E > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
include
yaclib
util
detail
spinlock.hpp
Generated by
1.9.8