25 #ifndef TERVEL_MEMORY_RC_UTIL_DESCRIPTOR_H_
26 #define TERVEL_MEMORY_RC_UTIL_DESCRIPTOR_H_
49 template<
typename DescrType,
typename... Args>
52 return rc_descr_pool->
get_descriptor<DescrType>(std::forward<Args>(args)...);
66 bool dont_check =
false) {
79 #ifdef TERVEL_MEM_RC_NO_WATCH
81 #endif // TERVEL_MEM_RC_NO_WATCH
84 assert(ref_count >=0 &&
" Ref count of an object is negative, which implies some thread called unwatch multiple times on the same object");
107 #ifdef TERVEL_MEM_RC_NO_WATCH
109 #endif // TERVEL_MEM_RC_NO_WATCH
114 if (address->load() != value) {
116 assert(temp > 0 &&
" Ref count of an object is negative, which implies some thread called unwatch multiple times on the same object");
119 bool res = descr->
on_watch(address, value);
121 assert(
is_watched(descr) &&
"On watch returned true, but the object is not watched. Error could exist on either [on_]watch or [on_]is_watched functions");
125 assert(temp > 0 &&
" Ref count of an object is negative, which implies some thread called unwatch multiple times on the same object");
140 #ifdef TERVEL_MEM_RC_NO_WATCH
142 #endif // TERVEL_MEM_RC_NO_WATCH
146 assert(temp > 0 &&
" Ref count of an object is negative, which implies some thread called unwatch multiple times on the same object");
158 return reinterpret_cast<void *
>(
reinterpret_cast<uintptr_t
>(descr) | 0x1L);
168 std::atomic<uintptr_t> *temp =
reinterpret_cast<std::atomic<uintptr_t> *
>(address);
180 reinterpret_cast<uintptr_t
>(descr) & ~0x1L);
190 return (0x1L == (reinterpret_cast<uintptr_t>(descr) & 0x1L));
215 if (
watch(descr, address, expected)) {
216 newValue = descr->
complete(expected, address);
219 newValue = address->load();
234 void *current_value = address->load();
244 reinterpret_cast<tervel::util::OpRecord *>(op));
245 current_value = op->
load();
247 return current_value;
250 if (
watch(descr, address, current_value)) {
254 current_value = address->load();
258 return current_value;
267 #endif // TERVEL_MEMORY_RC_UTIL_DESCRIPTOR_H_
DescrType * get_descriptor(Args &&...args)
Constructs and returns a descriptor.
Definition: descriptor_util.h:50
virtual void * get_logical_value()=0
This method is implemented by each sub class.
virtual void on_unwatch()
This method must be implemented if on_watch is implemented, and is optional otherwise.
Definition: descriptor.h:109
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 * mark_first(tervel::util::Descriptor *descr)
This returns the passed reference with its least signifcant bit set to 1.
Definition: descriptor_util.h:157
util::memory::rc::DescriptorPool *const get_rc_descriptor_pool()
void free_descriptor(tervel::util::Descriptor *descr, bool dont_check=false)
Once a user is done with a descriptor, they should free it with this method.
Definition: descriptor_util.h:65
void atomic_mark_first(std::atomic< void * > *address)
This function atomically bit marks the value at address.
Definition: descriptor_util.h:167
TODO(steven):
Definition: mcas.h:36
Helper class for RAII management of recursive helping of threads.
Definition: recursive_action.h:38
void unwatch(tervel::util::Descriptor *descr)
This method is used to decrement the reference count of the passed descriptor object.
Definition: descriptor_util.h:139
Header & header()
A reference to the header which houses all the special info.
Definition: pool_element.h:90
void free_descriptor(tervel::util::Descriptor *descr, bool dont_check=false)
Once a user is done with a descriptor, they should free it with this method.
virtual bool on_is_watched()
This method is optional to implement for each sub class.
Definition: descriptor.h:117
static void make_announcement(OpRecord *op, const uint64_t tid=tervel::tl_thread_info->get_thread_id(), ProgressAssurance *const prog_assur=tervel::tl_thread_info->get_progress_assurance())
This function places the.
Definition: progress_assurance.h:172
bool is_watched(tervel::util::Descriptor *descr)
This method is used to determine if the passed descriptor is under rc protection. ...
Definition: descriptor_util.h:78
static bool recursive_return(bool change=false, bool value=false)
This defines the Descriptor class, this class is designed to be extend and be used in conjunction wit...
Definition: descriptor.h:60
__thread ThreadContext * tl_thread_info
tervel::util::Descriptor * unmark_first(void *descr)
This returns an unbitmarked reference.
Definition: descriptor_util.h:178
virtual void * complete(void *current, std::atomic< void * > *address)=0
This method is implemented by each sub class and must guarantee that upon return that the descriptor ...
void safe_delete(bool no_check=false, ElementList *const element_list=tervel::tl_thread_info->get_hp_element_list())
This function is used to free a hazard pointer protected object if it is safe to do so OR add it to a...
Definition: hp_element.h:67
void * descriptor_read_first(std::atomic< void * > *address)
This function determines the logical value of an address which may have either a RC descriptor or a n...
Definition: descriptor_util.h:233
bool watch(tervel::util::Descriptor *descr, std::atomic< void * > *address, void *value)
This method is used to increment the reference count of the passed descriptor object.
Definition: descriptor_util.h:105
bool is_descriptor_first(void *descr)
This returns whether or not the least significant bit holds a bitmark.
Definition: descriptor_util.h:189
This class is used to hold the memory management information (Header) and a descriptor object...
Definition: pool_element.h:46
DescrType * get_descriptor(Args &&...args)
Constructs and returns a descriptor.
Definition: descriptor_pool.h:212
virtual bool on_watch(std::atomic< void * > *, void *)
This method is optional to implement for each sub class.
Definition: descriptor.h:99
void * remove_descriptor(void *expected, std::atomic< void * > *address)
This method is used to remove a descriptor object that is conflict with another threads operation...
Definition: descriptor_util.h:208
bool isDelayed(size_t val=1)
Definition: progress_assurance.h:125
Definition: progress_assurance.h:120
Class used for placement in the Op Table to complete an operation that failed to complete in a bounde...
Definition: descriptor_read_first_op.h:44