|
UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
|
A simple spinlock implementation using std::atomic_flag. More...
#include <lib/utility/include/ufo/utility/spinlock.hpp>
Public Member Functions | |
| void | lock () noexcept |
| Acquires the lock. Spins until the lock is available. | |
| bool | try_lock () noexcept |
| Attempts to acquire the lock without blocking. | |
| void | unlock () noexcept |
| Releases the lock and notifies one waiting thread. | |
A simple spinlock implementation using std::atomic_flag.
Spinlock is a lightweight mutual exclusion primitive for short critical sections. It repeatedly checks a flag until it can acquire the lock, avoiding thread suspension.
Uses C++20 atomic wait/notify for efficient spinning.
Example usage:
Definition at line 67 of file spinlock.hpp.
|
noexcept |
Acquires the lock. Spins until the lock is available.
Uses atomic wait/notify for efficient spinning.
BSD 3-Clause License
Copyright (c) 2020-2026, Daniel Duberg All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition at line 47 of file spinlock.cpp.
|
noexcept |
Attempts to acquire the lock without blocking.
Definition at line 54 of file spinlock.cpp.
|
noexcept |
Releases the lock and notifies one waiting thread.
Definition at line 59 of file spinlock.cpp.