1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/pattern/LockFreeBufferMisc.hpp" 5 #include "hmbdc/os/Allocators.hpp" 7 #include "hmbdc/Config.hpp" 15 namespace hmbdc {
namespace pattern {
17 template <u
int16_t MAX_PARALLE_CONSUMER>
19 using Sequence = HMBDC_SEQ_TYPE;
21 using value_type =
void *;
24 max_parallel_consumer = MAX_PARALLE_CONSUMER
27 template <
typename Allocator = os::DefaultAllocator>
28 LockFreeBufferT(
size_t, uint32_t, Allocator& allocator = os::DefaultAllocator::instance);
31 size_t capacity()
const;
32 size_t maxItemSize()
const;
34 void put(
void const*,
size_t sizeHint = 0);
35 template <
typename T>
void put(T
const& item) {put(&item,
sizeof(T));}
36 template <
typename T>
void putSome(T
const& item) {put(&item, std::min(
sizeof(item), maxItemSize()));}
38 bool tryPut(
void const*,
size_t sizeHint = 0);
39 template <
typename T>
bool tryPut(T
const& item) {
return tryPut(&item,
sizeof(T));}
41 void killPut(
void const*,
size_t sizeHint = 0);
43 template <
typename T>
void killPut(T
const& item) {killPut(&item,
sizeof(T));}
45 template <
typename T,
typename ...Args>
46 void putInPlace(Args&&... args) {
48 new (*s) T(std::forward<Args>(args)...);
52 template <
typename T,
typename ...Args>
53 bool tryPutInPlace(Args&&... args) {
56 new (*s) T(std::forward<Args>(args)...);
62 Sequence readSeq(uint16_t PARALLEL_CONSUMER_INDEX)
const;
71 void markDead(uint16_t);
74 T take(uint16_t PARALLEL_CONSUMER_INDEX) {
76 take(PARALLEL_CONSUMER_INDEX, &res,
sizeof(res));
80 void take(uint16_t PARALLEL_CONSUMER_INDEX,
void *,
size_t = 0);
81 void takeReentrant(uint16_t PARALLEL_CONSUMER_INDEX,
void *,
size_t = 0);
82 iterator peek(uint16_t PARALLEL_CONSUMER_INDEX)
const;
84 ,
size_t maxPeekSize = std::numeric_limits<size_t>::max())
const;
85 void waste(uint16_t PARALLEL_CONSUMER_INDEX,
size_t);
86 void wasteAfterPeek(uint16_t PARALLEL_CONSUMER_INDEX,
size_t);
87 Sequence catchUpWith(uint16_t PARALLEL_CONSUMER_INDEX, uint16_t);
88 void catchUpTo(uint16_t PARALLEL_CONSUMER_INDEX, Sequence);
90 size_t remainingSize(uint16_t PARALLEL_CONSUMER_INDEX)
const;
91 size_t remainingSize()
const;
92 size_t parallelConsumerAlive()
const;
93 void reset(uint16_t PARALLEL_CONSUMER_INDEX);
96 size_t footprint(
size_t, uint32_t);
100 unusedConsumerIndexes()
const;
103 takeUnusedConsumer();
106 std::ptrdiff_t impl_;
107 bool allocateFromHeap_;
Definition: LockFreeBufferMisc.hpp:23
Definition: LockFreeBufferT.hpp:18
Definition: LockFreeBufferMisc.hpp:89