25 #ifndef TERVEL_UTIL_MEMORY_RC_POOL_ELEMENT_H_
26 #define TERVEL_UTIL_MEMORY_RC_POOL_ELEMENT_H_
57 std::atomic<bool> descriptor_in_use {
false};
58 std::atomic<uint64_t> allocation_count {0};
59 std::atomic<uint64_t> free_count {0};
66 assert(this->
header().ref_count.load() == 0);
70 assert(
false &&
"PoolElement should never be deleted, return it to Tervel please");
110 template<
typename DescrType,
typename... Args>
126 "Pool elements should be cache-aligned. Padding calculation is probably"
146 template<
typename DescrType,
typename... Args>
148 static_assert(
sizeof(DescrType) <=
sizeof(
padding_),
149 "Descriptor is too large to use in a pool element");
151 this->
header().descriptor_in_use.store(
true);
153 new(
descriptor()) DescrType(std::forward<Args>(args)...);
159 assert(this->
header().descriptor_in_use.load());
160 this->
header().descriptor_in_use.store(
false);
169 assert(elem->
header().debug_pool_stamp == DEBUG_EXPECTED_STAMP &&
170 "Tried to get a PoolElement from a descriptor which does not have an "
171 "associated one. This probably means the user is attempting to free the "
172 "descriptor through a DescriptorPool but the descriptor wasn't allocated "
173 "through a DescriptorPool to begin with.");
184 #endif // TERVEL_UTIL_MEMORY_RC_POOL_ELEMENT_H_
void next(PoolElement *next)
Helper method for setting the next pointer.
Definition: pool_element.h:100
PoolElement(PoolElement *next=nullptr)
Definition: pool_element.h:64
PoolElement * get_elem_from_descriptor(tervel::util::Descriptor *descr)
If the given descriptor was allocated through a DescriptorPool, then it has an associated PoolElement...
Definition: pool_element.h:166
void cleanup_descriptor()
Should be called by the owner of this element when the descriptor in this element is no longer needed...
Definition: pool_element.h:157
Descriptor * descriptor()
Returns a pointer to the associated descriptor of this element.
Definition: pool_element.h:83
TODO(steven):
Definition: mcas.h:36
Header & header()
A reference to the header which houses all the special info.
Definition: pool_element.h:90
This defines the Descriptor class, this class is designed to be extend and be used in conjunction wit...
Definition: descriptor.h:60
#define CACHE_LINE_SIZE
Definition: system.h:41
PoolElement * next()
Helper method for getting the next pointer.
Definition: pool_element.h:95
This class is used to hold the memory management information (Header) and a descriptor object...
Definition: pool_element.h:46
~PoolElement()
Definition: pool_element.h:69
void init_descriptor(Args &&...args)
Constructs a descriptor of the given type within this pool element.
Definition: pool_element.h:147
char padding_[CACHE_LINE_SIZE-sizeof(Header)]
Definition: pool_element.h:120
virtual ~Descriptor()
Definition: descriptor.h:63
DISALLOW_COPY_AND_ASSIGN(PoolElement)
Header header_
Definition: pool_element.h:121
const long DEBUG_EXPECTED_STAMP
Definition: pool_element.h:38