8#include "../utility/utility.hpp"
9#include "../macros.hpp"
13hi_export_module(hikogui.concurrency.id_factory);
15hi_export
namespace hi {
inline namespace v1 {
24template<std::
unsigned_
integral T>
40 [[nodiscard]] value_type
acquire() noexcept
42 auto expected = _released_count.
load(std::memory_order::relaxed);
46 if (_released_count.
compare_exchange_weak(expected, expected - 1, std::memory_order::acquire, std::memory_order::relaxed)) {
52 hi_axiom(not _released.
empty());
55 auto const tmp = _released.
back();
64 _released_count.
fetch_add(1, std::memory_order::relaxed);
69 auto const tmp = _v.
fetch_add(1, std::memory_order::relaxed) + 1;
70 hi_assert(tmp != 0,
"id_factory overflow.");
84 auto const lock = std::scoped_lock(_mutex);
86 _released_count.
fetch_add(1, std::memory_order::release);
Definition of the unfair_mutex.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
A factory for unique IDs.
Definition id_factory.hpp:25
value_type operator++() noexcept
Definition id_factory.hpp:91
void release(value_type v) noexcept
Release an ID for reuse.
Definition id_factory.hpp:82
value_type acquire() noexcept
Get the next ID.
Definition id_factory.hpp:40
bool try_lock() noexcept
When try_lock() is called from a thread that already owns the lock it will return false.
Definition unfair_mutex_impl.hpp:216
T compare_exchange_weak(T... args)