31template <std::
size_t LaneCount>
33 static_assert(LaneCount > 0,
"ActivityChannel must have at least one lane");
34 static_assert(std::atomic<std::uint32_t>::is_always_lock_free,
35 "ActivityChannel requires lock-free 32-bit atomics");
40 static constexpr std::size_t
lane_count() noexcept {
return LaneCount; }
44 void signal(std::size_t lane)
noexcept {
45 if (lane >= LaneCount)
return;
46 sequences_[lane].fetch_add(1, std::memory_order_relaxed);
51 if (lane >= LaneCount)
return 0;
52 return sequences_[lane].load(std::memory_order_relaxed);
67 if (lane >= LaneCount)
return 0;
69 const Sequence count = current - cursor;
75 std::array<std::atomic<Sequence>, LaneCount> sequences_{};
78template <std::
size_t LaneCount>
81template <std::
size_t LaneCount>
83 return std::make_shared<ActivityChannel<LaneCount>>();
A fixed set of lock-free occurrence counters.
Definition activity_channel.hpp:32
Sequence consume_count(std::size_t lane, Sequence &cursor) const noexcept
Return the number of signals since cursor and advance it to the newest sequence.
Definition activity_channel.hpp:66
void signal(std::size_t lane) noexcept
Record activity on lane.
Definition activity_channel.hpp:44
Sequence sequence(std::size_t lane) const noexcept
Read the current sequence for lane. Invalid lanes read as zero.
Definition activity_channel.hpp:50
bool consume(std::size_t lane, Sequence &cursor) const noexcept
Return true once when activity has occurred since cursor was last consumed, updating the cursor to th...
Definition activity_channel.hpp:59
static constexpr std::size_t lane_count() noexcept
Definition activity_channel.hpp:40
std::uint32_t Sequence
Definition activity_channel.hpp:38
Definition generated_event_source.hpp:33
std::shared_ptr< ActivityChannel< LaneCount > > SharedActivityChannel
Definition activity_channel.hpp:79
SharedActivityChannel< LaneCount > make_activity_channel()
Definition activity_channel.hpp:82