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
47void 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
55{
56 return !flag_.test_and_set(std::memory_order_acquire);
57}
58
59void ufo::Spinlock::unlock() noexcept
60{
61 flag_.clear(std::memory_order_release);
62 flag_.notify_one();
63}
bool try_lock() noexcept
Attempts to acquire the lock without blocking.
Definition spinlock.cpp:54
void lock() noexcept
Acquires the lock. Spins until the lock is available.
Definition spinlock.cpp:47
void unlock() noexcept
Releases the lock and notifies one waiting thread.
Definition spinlock.cpp:59