1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/os/Allocators.hpp" 16 #ifndef SMP_CACHE_BYTES 17 #define SMP_CACHE_BYTES 64 20 namespace hmbdc {
namespace pattern {
25 : std::runtime_error(what_arg){}
28 template <
typename Seq>
30 template<
typename Allocator = os::DefaultAllocator>
31 chunk_base_ptr(uint32_t valueTypeSizePower2Num, uint32_t ringSizePower2Num
32 , Allocator& allocator = os::DefaultAllocator::instance)
33 : space_((
char*)allocator.memalign(SMP_CACHE_BYTES, (1u << valueTypeSizePower2Num) * (1u << ringSizePower2Num))
35 , MASK((1u << ringSizePower2Num) - 1)
36 , valueTypeSizePower2Num_(valueTypeSizePower2Num)
37 , allocateFromHeap_(Allocator::fromHeap) {
40 static size_t footprint(uint32_t valueTypeSizePower2Num, uint32_t ringSizePower2Num) {
42 + (1u << valueTypeSizePower2Num) * (1u << ringSizePower2Num);
46 if (allocateFromHeap_) {
47 ::free(((
char*
const)
this) + space_);
51 void* operator + (
size_t index)
const __restrict__ {
52 return (((
char*
const)
this) + space_) + (index << valueTypeSizePower2Num_) +
sizeof(Seq);
55 Seq* getSeq(
size_t index)
const __restrict__ {
56 return reinterpret_cast<Seq*
>((((
char*
const)
this) + space_) + (index << valueTypeSizePower2Num_));
60 size_t operator - (
void const* __restrict__ from,
chunk_base_ptr<Seq> const& __restrict__ start) {
61 return (static_cast<char const*>(from) -
sizeof(Seq) - (((
char*
const)&start) + start.space_))
62 >> start.valueTypeSizePower2Num_;
64 std::ptrdiff_t
const space_;
66 uint32_t
const valueTypeSizePower2Num_;
67 bool allocateFromHeap_;
70 } __attribute__((__aligned__(SMP_CACHE_BYTES)));
72 template <
typename Seq>
80 : start_(&start), seq_(seq){}
81 iterator() : start_(
nullptr), seq_(0){}
82 Seq seq()
const {
return seq_;}
83 void clear() {start_ =
nullptr;}
85 iterator& operator ++() __restrict__ {
90 iterator operator ++(
int) __restrict__ {
96 iterator operator + (
size_t dis)
const __restrict__ {
102 size_t operator - (
iterator const& other)
const __restrict__ {
103 return seq_ - other.seq_;
106 explicit operator bool()
const __restrict__ {
110 bool operator < (
iterator const& other)
const __restrict__ {
111 return seq_ < other.seq_;
114 bool operator == (
iterator const& other)
const __restrict__ {
return seq_ == other.seq_;}
115 bool operator != (
iterator const& other)
const __restrict__ {
return seq_ != other.seq_;}
116 void* operator*()
const __restrict__ {
return *start_ + (seq_ & start_->MASK);}
117 template <
typename T> T&
get()
const __restrict__ {
return *
static_cast<T*
>(**this); }
118 template <
typename T>
119 T* operator->() __restrict__ {
return static_cast<T*
>(*start_ + (seq_ & start_->MASK));}
Definition: LockFreeBufferMisc.hpp:29
Definition: LockFreeBufferMisc.hpp:23
Definition: Client.hpp:11
Definition: LockFreeBufferMisc.hpp:73