bux API Reference
1.9.0
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Loading...
Searching...
No Matches
src
AtomiX.cpp
Go to the documentation of this file.
1
#include "
AtomiX.h
"
2
3
namespace
bux
{
4
5
//
6
// Implement Classes
7
//
8
C_SpinLock::C_SpinLock
(std::atomic_flag &lock_): m_lock(&lock_)
9
{
10
while
(lock_.test_and_set(std::memory_order_acquire))
// acquire lock
11
#ifdef __cpp_lib_atomic_flag_test
12
// Since C++20, it is possible to update atomic_flag's
13
// value only when there is a chance to acquire the lock.
14
// See also: https://stackoverflow.com/questions/62318642
15
while (lock_.test(std::memory_order_relaxed))
// test lock
16
#endif
17
;
// spin
18
}
19
20
void
C_SpinLock::unlock
()
21
{
22
if
(m_lock)
23
{
24
m_lock->clear(std::memory_order_release);
// release lock
25
m_lock =
nullptr
;
26
}
27
}
28
29
}
// namespace bux
AtomiX.h
bux::C_SpinLock::C_SpinLock
C_SpinLock(std::atomic_flag &lock_)
Definition
AtomiX.cpp:8
bux::C_SpinLock::unlock
void unlock()
Definition
AtomiX.cpp:20
bux
THE common namespace of bux library.
Definition
AtomiX.cpp:3
Generated by
1.12.0