9#include <atomic_queue/include/atomic_queue/atomic_queue.h>
15#include <oneapi/tbb/concurrent_map.h>
16#include <phmap/parallel_hashmap/phmap.h>
52 if (_buffer !=
nullptr) free(_buffer);
59 __JAFFAR_COMMON_INLINE__
void reserve(
const size_t capacity)
62 _buffer = (T*)malloc(capacity *
sizeof(T));
69 __JAFFAR_COMMON_INLINE__
void clear()
72 _claim.store(0, std::memory_order_relaxed);
95 uint64_t observed = _claim.load(std::memory_order_acquire);
100 front = (uint32_t)(observed & 0xFFFFFFFFULL);
101 const uint32_t back = (uint32_t)(observed >> 32);
102 if ((
size_t)front + (size_t)back >= _count)
return 0;
103 const size_t available = _count - (size_t)front - (
size_t)back;
104 take = maxCount < available ? maxCount : available;
105 desired = (observed & 0xFFFFFFFF00000000ULL) | (uint64_t)(front + (uint32_t)take);
106 }
while (_claim.compare_exchange_weak(observed, desired, std::memory_order_acq_rel, std::memory_order_acquire) ==
false);
108 memcpy(elements, &_buffer[front], take *
sizeof(T));
126 uint64_t observed = _claim.load(std::memory_order_acquire);
130 const uint32_t front = (uint32_t)(observed & 0xFFFFFFFFULL);
131 back = (uint32_t)(observed >> 32);
132 if ((
size_t)front + (size_t)back >= _count)
return false;
133 desired = (observed & 0x00000000FFFFFFFFULL) | ((uint64_t)(back + 1) << 32);
134 }
while (_claim.compare_exchange_weak(observed, desired, std::memory_order_acq_rel, std::memory_order_acquire) ==
false);
136 element = _buffer[_count - 1 - (size_t)back];
145 __JAFFAR_COMMON_INLINE__
size_t wasSize()
const
147 const uint64_t observed = _claim.load(std::memory_order_relaxed);
148 const size_t claimed = (size_t)(observed & 0xFFFFFFFFULL) + (size_t)(observed >> 32);
149 return claimed >= _count ? 0 : _count - claimed;
156 T* _buffer =
nullptr;
161 size_t _capacity = 0;
172 std::atomic<uint64_t> _claim{0};
185using HashSet_t = phmap::parallel_flat_hash_set<V, phmap::priv::hash_default_hash<V>, phmap::priv::hash_default_eq<V>, std::allocator<V>, 8, std::mutex>;
190template <
class K,
class V>
191using HashMap_t = phmap::parallel_flat_hash_map<K, V, phmap::priv::hash_default_hash<K>, phmap::priv::hash_default_eq<K>, std::allocator<std::pair<const K, V>>, 8, std::mutex>;
196template <
class K,
class V,
class C = std::greater<K>>
226 _internalDeque.push_back(element);
227 _size.fetch_add(1, std::memory_order_relaxed);
240 _internalDeque.push_back(element);
241 _size.fetch_add(1, std::memory_order_relaxed);
254 _internalDeque.push_front(element);
255 _size.fetch_add(1, std::memory_order_relaxed);
268 _internalDeque.push_front(element);
269 _size.fetch_add(1, std::memory_order_relaxed);
281 __JAFFAR_COMMON_INLINE__ T
front()
const {
return _internalDeque.front(); }
291 __JAFFAR_COMMON_INLINE__ T
back()
const {
return _internalDeque.back(); }
302 _internalDeque.pop_front();
303 _size.fetch_sub(1, std::memory_order_relaxed);
316 _internalDeque.pop_back();
317 _size.fetch_sub(1, std::memory_order_relaxed);
332 if (_internalDeque.empty())
338 element = _internalDeque.back();
339 _internalDeque.pop_back();
340 _size.fetch_sub(1, std::memory_order_relaxed);
357 if (_internalDeque.empty())
363 element = _internalDeque.front();
364 _internalDeque.pop_front();
365 _size.fetch_sub(1, std::memory_order_relaxed);
391 while (count < maxCount && _internalDeque.empty() ==
false)
393 elements[count++] = _internalDeque.front();
394 _internalDeque.pop_front();
396 if (count > 0) _size.fetch_sub(count, std::memory_order_relaxed);
410 __JAFFAR_COMMON_INLINE__
size_t wasSize()
const {
return _size.load(std::memory_order_relaxed); }
422 std::atomic<size_t> _size{0};
427 std::deque<T> _internalDeque;
Definition concurrent.hpp:206
__JAFFAR_COMMON_INLINE__ bool pop_front_get(T &element)
Definition concurrent.hpp:353
__JAFFAR_COMMON_INLINE__ void pop_front()
Definition concurrent.hpp:299
__JAFFAR_COMMON_INLINE__ void push_back(T element)
Definition concurrent.hpp:237
__JAFFAR_COMMON_INLINE__ size_t pop_front_get_batch(T *elements, const size_t maxCount)
Definition concurrent.hpp:386
__JAFFAR_COMMON_INLINE__ auto & getInternalStorage()
Definition concurrent.hpp:215
__JAFFAR_COMMON_INLINE__ void push_front(T element)
Definition concurrent.hpp:265
__JAFFAR_COMMON_INLINE__ bool pop_back_get(T &element)
Definition concurrent.hpp:328
__JAFFAR_COMMON_INLINE__ size_t wasSize() const
Definition concurrent.hpp:410
__JAFFAR_COMMON_INLINE__ void push_front_no_lock(T element)
Definition concurrent.hpp:252
__JAFFAR_COMMON_INLINE__ T front() const
Definition concurrent.hpp:281
__JAFFAR_COMMON_INLINE__ void push_back_no_lock(T element)
Definition concurrent.hpp:224
__JAFFAR_COMMON_INLINE__ void pop_back()
Definition concurrent.hpp:313
__JAFFAR_COMMON_INLINE__ T back() const
Definition concurrent.hpp:291
Definition concurrent.hpp:47
__JAFFAR_COMMON_INLINE__ size_t pop_front_get_batch(T *elements, const size_t maxCount)
Definition concurrent.hpp:93
__JAFFAR_COMMON_INLINE__ void clear()
Definition concurrent.hpp:69
__JAFFAR_COMMON_INLINE__ bool pop_front_get(T &element)
Definition concurrent.hpp:117
__JAFFAR_COMMON_INLINE__ void push_back_no_lock(T element)
Definition concurrent.hpp:83
__JAFFAR_COMMON_INLINE__ size_t wasSize() const
Definition concurrent.hpp:145
__JAFFAR_COMMON_INLINE__ bool pop_back_get(T &element)
Definition concurrent.hpp:124
__JAFFAR_COMMON_INLINE__ void reserve(const size_t capacity)
Definition concurrent.hpp:59
atomic_queue::AtomicQueueB< T > atomicQueue_t
Definition concurrent.hpp:179
oneapi::tbb::concurrent_multimap< K, V, C > concurrentMultimap_t
Definition concurrent.hpp:197
phmap::parallel_flat_hash_set< V, phmap::priv::hash_default_hash< V >, phmap::priv::hash_default_eq< V >, std::allocator< V >, 8, std::mutex > HashSet_t
Definition concurrent.hpp:185
phmap::parallel_flat_hash_map< K, V, phmap::priv::hash_default_hash< K >, phmap::priv::hash_default_eq< K >, std::allocator< std::pair< const K, V > >, 8, std::mutex > HashMap_t
Definition concurrent.hpp:191