UFO
1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
spinlock.cpp
1
41
// UFO
42
#include <ufo/utility/spinlock.hpp>
43
44
// STL
45
#include <atomic>
46
47
void
ufo::Spinlock::lock
() noexcept
48
{
49
while
(flag_.test_and_set(std::memory_order_acquire)) {
50
flag_.wait(
true
, std::memory_order_relaxed);
51
}
52
}
53
54
bool
ufo::Spinlock::try_lock
() noexcept
55
{
56
return
!flag_.test_and_set(std::memory_order_acquire);
57
}
58
59
void
ufo::Spinlock::unlock
() noexcept
60
{
61
flag_.clear(std::memory_order_release);
62
flag_.notify_one();
63
}
ufo::Spinlock::try_lock
bool try_lock() noexcept
Attempts to acquire the lock without blocking.
Definition
spinlock.cpp:54
ufo::Spinlock::lock
void lock() noexcept
Acquires the lock. Spins until the lock is available.
Definition
spinlock.cpp:47
ufo::Spinlock::unlock
void unlock() noexcept
Releases the lock and notifies one waiting thread.
Definition
spinlock.cpp:59
lib
utility
src
spinlock.cpp
Generated by
1.9.8