20#include <boost/functional/hash/hash.hpp>
21#include <boost/io/ios_state.hpp>
31 m_id(create_unique_id())
56 using std::memory_order_relaxed;
65 static atomic<id_t> s_last_id{0};
66 return s_last_id.fetch_add(1, memory_order_relaxed) + 1;
73 static_assert(std::is_same_v<uint64_t, Unique_id_holder::id_t>,
74 "Thread_token wraps Unique_id_holder-supplied values; this check ensures no surprises: that "
75 "Unique_id_holder issues the type we expect.");
92 using boost::io::ios_all_saver;
97 ios_all_saver saver{os};
103 static_assert(
sizeof(uint32_t) == 4,
"4 bytes <=> 8 hex-chars.");
104 return os <<
"0x" << hex << setfill(
'0') << setw(8) << uint32_t(
Thread_token::id_t(val));
110 return hash<Thread_token::id_t>()(val);
Each object of this class stores (at construction) and returns (on demand) a numeric ID unique from a...
id_t unique_id() const
Raw unique ID identifying this object as well as any object of a derived type.
static id_t create_unique_id()
Short-hand for Unique_id_holder().unique_id(); useful when all you want is the unique integer itself.
Unique_id_holder()
Thread-safely construct an ID whose value is different from any other object of this class,...
const Unique_id_holder & operator=(const Unique_id_holder &) const
This assignment operator is a const no-op.
const id_t m_id
The ID. Note its constness alone forbids a classic assignment operator.
uint64_t id_t
Raw integer type to uniquely identify a thing. 64-bit width should make overflow extremely hard to re...
Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module...
std::ostream & operator<<(std::ostream &os, const Thread_local_state_registry< Thread_local_state_t > &val)
Serializes a Thread_local_state_registry to a standard output stream.
Thread_token this_thread_unique_token()
Returns a value conceptually similar to this_thread::get_id() – a thread ID – but that is never recyc...
size_t hash_value(Thread_token val)
Hashes the given Thread_token; making it, e.g., boost.unordered-compatible as a key out of the box.
An integer-like, type-safe wrapper for the thread-token concept – see this_thread_unique_token(),...
Unique_id_holder::id_t id_t
Short-hand for the underlying integer type.