Tervel  1.0.0
A collection of wait-free containers and algorithms.
Classes | Functions | Variables
tervel::util::memory::rc Namespace Reference

Classes

class  DescriptorPool
 Defines a pool of descriptor objects which is used to allocate descriptors and to store them while they are not safe to delete. More...
 
class  PoolElement
 This class is used to hold the memory management information (Header) and a descriptor object. More...
 
class  PoolManager
 A manager class for the reference count protected memory pools. More...
 
class  ReadFirstOp
 Class used for placement in the Op Table to complete an operation that failed to complete in a bounded number of steps. More...
 

Functions

template<typename DescrType , typename... Args >
DescrType * get_descriptor (Args &&...args)
 Constructs and returns a descriptor. More...
 
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. More...
 
bool is_watched (tervel::util::Descriptor *descr)
 This method is used to determine if the passed descriptor is under rc protection. More...
 
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. More...
 
void unwatch (tervel::util::Descriptor *descr)
 This method is used to decrement the reference count of the passed descriptor object. More...
 
void * mark_first (tervel::util::Descriptor *descr)
 This returns the passed reference with its least signifcant bit set to 1. More...
 
void atomic_mark_first (std::atomic< void * > *address)
 This function atomically bit marks the value at address. More...
 
tervel::util::Descriptorunmark_first (void *descr)
 This returns an unbitmarked reference. More...
 
bool is_descriptor_first (void *descr)
 This returns whether or not the least significant bit holds a bitmark. More...
 
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. More...
 
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 normal value. More...
 
PoolElementget_elem_from_descriptor (tervel::util::Descriptor *descr)
 If the given descriptor was allocated through a DescriptorPool, then it has an associated PoolElement header. More...
 

Variables

const long DEBUG_EXPECTED_STAMP = 0xDEADBEEF
 

Function Documentation

void tervel::util::memory::rc::atomic_mark_first ( std::atomic< void * > *  address)
inline

This function atomically bit marks the value at address.

This function atomically bit marks the value at address

Parameters
addressthe address to bitmark
void* tervel::util::memory::rc::descriptor_read_first ( std::atomic< void * > *  address)
inline

This function determines the logical value of an address which may have either a RC descriptor or a normal value.

Parameters
addressto read
Returns
the current logical value
void tervel::util::memory::rc::free_descriptor ( tervel::util::Descriptor descr,
bool  dont_check = false 
)
inline

Once a user is done with a descriptor, they should free it with this method.

Parameters
descrThe descriptor to free.
dont_checkDon't check if the descriptor is being watched before freeing it. Use this flag if you know that no other thread has had access to this descriptor.
poolthe pool to use when freeing the descriptor.
template<typename DescrType , typename... Args >
DescrType* tervel::util::memory::rc::get_descriptor ( Args &&...  args)
inline

Constructs and returns a descriptor.

Arguments are forwarded to the constructor of the given descriptor type. User should call free_descriptor on the returned pointer when they are done with it to avoid memory leaks.

PoolElement * tervel::util::memory::rc::get_elem_from_descriptor ( tervel::util::Descriptor descr)
inline

If the given descriptor was allocated through a DescriptorPool, then it has an associated PoolElement header.

This methods returns that PoolElement.

Use with caution as Descriptors not allocated from a pool will not have an associated header, and, thus, the returned value will be to some random place in memory.

Parameters
descrThe Descriptor pointer allocated through a descriptor pool which thus has an associated PoolElement.
Returns
The associated PoolElement.
bool tervel::util::memory::rc::is_descriptor_first ( void *  descr)
inline

This returns whether or not the least significant bit holds a bitmark.

Parameters
thereference to check
Returns
whether or not it holds a bitmark
bool tervel::util::memory::rc::is_watched ( tervel::util::Descriptor descr)
inline

This method is used to determine if the passed descriptor is under rc protection.

Internally calls on_is_watched

Parameters
descrthe descriptor to be checked for rc protection.
void* tervel::util::memory::rc::mark_first ( tervel::util::Descriptor descr)
inline

This returns the passed reference with its least signifcant bit set to 1.

Parameters
descrthe reference to bitmark
Returns
the bitmarked reference
void* tervel::util::memory::rc::remove_descriptor ( void *  expected,
std::atomic< void * > *  address 
)
inline

This method is used to remove a descriptor object that is conflict with another threads operation.

It first checks the recursive depth before proceeding. Next it protects against the object being reused else where by acquiring either HP or RC watch on the object. Then once it is safe it will call the objects complete function This function must guarantee that after its return the object has been removed It returns the value.

Parameters
expecteda marked reference to the object
addressthe location expected was read from dereferenced from.
Returns
the current value of the address
tervel::util::Descriptor* tervel::util::memory::rc::unmark_first ( void *  descr)
inline

This returns an unbitmarked reference.

Parameters
thereference to remove the bitmark from
Returns
the unbitmarked reference
void tervel::util::memory::rc::unwatch ( tervel::util::Descriptor descr)
inline

This method is used to decrement the reference count of the passed descriptor object.

Then it will call on_unwatch and decrement any related objects necessary Internally calls on_unwatch

Parameters
descrthe descriptor which no longer needs rc protection.
bool tervel::util::memory::rc::watch ( tervel::util::Descriptor descr,
std::atomic< void * > *  address,
void *  value 
)
inline

This method is used to increment the reference count of the passed descriptor object.

If after incrementing the reference count the object is still at the address (indicated by *a == value), it will call on_watch. If that returns true then it will return true. Otherwise it decrements the reference count and returns false Internally calls on_watch

Parameters
descrthe descriptor which needs rc protection
addressaddress it was dereferenced from
valthe read value of the address
Returns
true if successfully acquired a watch

Variable Documentation

const long tervel::util::memory::rc::DEBUG_EXPECTED_STAMP = 0xDEADBEEF