56class lock_free_spmc_ring_buffer_base: util::NonCopyable
65 lock_free_spmc_ring_buffer_base(
size_t capacity);
66 ~lock_free_spmc_ring_buffer_base() =
default;
68 typedef num::Tuint32 index_type;
70 struct alignas(8) tagged_index_t
72 tagged_index_t() noexcept {}
73 tagged_index_t(index_type index, index_type tag) : index(index), tag(tag) {}
77 static bool empty(tagged_index_t head, tagged_index_t tail) {
return head.index == tail.index && head.tag == tail.tag; }
78 static bool full(tagged_index_t head, tagged_index_t tail) {
return head.index == tail.index && head.tag != tail.tag; }
82 tagged_index_t next_index(tagged_index_t index)
const;
84 alignas(LASS_LOCK_FREE_ALIGNMENT) std::atomic<tagged_index_t> head_;
85 alignas(LASS_LOCK_FREE_ALIGNMENT) std::atomic<tagged_index_t> tail_;
86 const index_type ring_size_;
90 static_assert(
sizeof(tagged_index_t) == 8,
"tagged_index_t should be 8-bytes");
92 static size_t enforce_valid_size(
size_t size);
99class lock_free_spmc_value_ring_buffer:
private lock_free_spmc_ring_buffer_base
102 typedef T value_type;
104 lock_free_spmc_value_ring_buffer(
size_t capacity);
105 ~lock_free_spmc_value_ring_buffer() =
default;
107 bool try_push(
const value_type& x);
108 bool try_push(value_type&& x);
109 template <
class... Args>
bool try_emplace(Args&&... args);
110 bool try_pop(value_type& x);
112 using lock_free_spmc_ring_buffer_base::empty;
113 using lock_free_spmc_ring_buffer_base::full;
117 std::vector< std::atomic<value_type> > ring_;
124 typename FixedAllocator = util::AllocatorConcurrentFreeList<>
126class lock_free_spmc_object_ring_buffer:
private lock_free_spmc_ring_buffer_base
129 typedef T value_type;
131 lock_free_spmc_object_ring_buffer(
size_t capacity);
132 ~lock_free_spmc_object_ring_buffer();
134 bool try_push(
const value_type& x);
135 bool try_push(value_type&& x);
136 template <
class... Args>
bool try_emplace(Args&&... args);
137 bool try_pop(value_type& x);
139 using lock_free_spmc_ring_buffer_base::empty;
140 using lock_free_spmc_ring_buffer_base::full;
144 FixedAllocator value_allocator_;
145 std::vector< std::atomic<T*> > ring_;
151using lock_free_spmc_ring_buffer =
typename std::conditional<
152 std::is_trivially_copy_constructible<T>::value,
153 impl::lock_free_spmc_value_ring_buffer<T>,
154 impl::lock_free_spmc_object_ring_buffer<T>
lass extensions to the standard library
Library for Assembled Shared Sources.