Tervel  1.0.0
A collection of wait-free containers and algorithms.
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
tervel::util::memory::hp::HazardPointer Class Reference

This class is used to maintain the list of hazard pointed objects. More...

#include <hazard_pointer.h>

Public Types

enum  SlotID : size_t { SlotID::SHORTUSE = 0, SlotID::SHORTUSE2, SlotID::PROG_ASSUR, SlotID::END }
 

Public Member Functions

 HazardPointer (int num_threads)
 
 ~HazardPointer ()
 
void watch (SlotID slot, void *value)
 This function takes a SlotID and stores the specified value into that the threads alloted slot for that id in the hazard pointer watch list. More...
 
void clear_watch (SlotID slot)
 This function takes a SlotID and stores null into that the threads alloted slot for that id in the hazard pointer watch list. More...
 
bool contains (void *value)
 This function returns true of the specified value is being watched. More...
 
 DISALLOW_COPY_AND_ASSIGN (HazardPointer)
 

Static Public Member Functions

static bool watch (SlotID slot_id, Element *elem, std::atomic< void * > *address, void *expected, HazardPointer *const hazard_pointer=tervel::tl_thread_info->get_hazard_pointer())
 This method is used to achieve a hazard pointer watch on the the based descr. More...
 
static bool watch (SlotID slot_id, void *value, std::atomic< void * > *address, void *expected, HazardPointer *const hazard_pointer=tervel::tl_thread_info->get_hazard_pointer())
 This method is used to achieve a hazard pointer watch on a memory address. More...
 
static void unwatch (SlotID slot_id, HazardPointer *const hazard_pointer=tervel::tl_thread_info->get_hazard_pointer())
 This method is used to remove the hazard pointer watch. More...
 
static void unwatch (SlotID slot_id, Element *descr, HazardPointer *const hazard_pointer=tervel::tl_thread_info->get_hazard_pointer())
 This method is used to remove the hazard pointer watch. More...
 
static bool is_watched (Element *descr, HazardPointer *const hazard_pointer=tervel::tl_thread_info->get_hazard_pointer())
 This method is used to determine if a hazard pointer watch exists on a passed value. More...
 
static bool is_watched (void *value, HazardPointer *const hazard_pointer=tervel::tl_thread_info->get_hazard_pointer())
 This method is used to determine if a hazard pointer watch exists on a passed value. More...
 

Public Attributes

util::memory::hp::ListManager hp_list_manager_
 

Private Member Functions

size_t get_slot (SlotID id)
 This function calculates a the position of a threads slot for the specified SlotID. More...
 

Private Attributes

std::unique_ptr< std::atomic< void * >[]> watches_
 
const size_t num_slots_
 

Detailed Description

This class is used to maintain the list of hazard pointed objects.

Any value can be written into a slot, however we provide special implementation for Elements, in that we call their on_* functions. This allows for more expressive operations to be performed.

If an individual thread requires more than one element to be hazard pointer protected at a single instance, then SlotIDs should be added.

Member Enumeration Documentation

Enumerator
SHORTUSE 
SHORTUSE2 
PROG_ASSUR 
END 

Constructor & Destructor Documentation

tervel::util::memory::hp::HazardPointer::HazardPointer ( int  num_threads)
explicit
tervel::util::memory::hp::HazardPointer::~HazardPointer ( )

Member Function Documentation

void tervel::util::memory::hp::HazardPointer::clear_watch ( SlotID  slot)
inline

This function takes a SlotID and stores null into that the threads alloted slot for that id in the hazard pointer watch list.

Parameters
slotThe id of the slot to watch.
bool tervel::util::memory::hp::HazardPointer::contains ( void *  value)
inline

This function returns true of the specified value is being watched.

Parameters
valueThe value to check.
Returns
true is the table contains the specified value
tervel::util::memory::hp::HazardPointer::DISALLOW_COPY_AND_ASSIGN ( HazardPointer  )
size_t tervel::util::memory::hp::HazardPointer::get_slot ( SlotID  id)
inlineprivate

This function calculates a the position of a threads slot for the specified SlotID.

Parameters
slotThe slot id to get the position of
static bool tervel::util::memory::hp::HazardPointer::is_watched ( Element descr,
HazardPointer *const  hazard_pointer = tervel::tl_thread_info->get_hazard_pointer() 
)
static

This method is used to determine if a hazard pointer watch exists on a passed value.

If a descr is passed then it will internally call descr->on_is_watched.

Parameters
descrto call on_is_watched on.
static bool tervel::util::memory::hp::HazardPointer::is_watched ( void *  value,
HazardPointer *const  hazard_pointer = tervel::tl_thread_info->get_hazard_pointer() 
)
static

This method is used to determine if a hazard pointer watch exists on a passed value.

If a descr is passed then it will internally call descr->on_is_watched.

Parameters
valueto check if watch
static void tervel::util::memory::hp::HazardPointer::unwatch ( SlotID  slot_id,
HazardPointer *const  hazard_pointer = tervel::tl_thread_info->get_hazard_pointer() 
)
static

This method is used to remove the hazard pointer watch.

If a descr is passed then it will internally call descr->on_unwatch.

Parameters
slotthe slot to remove the watch
static void tervel::util::memory::hp::HazardPointer::unwatch ( SlotID  slot_id,
Element descr,
HazardPointer *const  hazard_pointer = tervel::tl_thread_info->get_hazard_pointer() 
)
static

This method is used to remove the hazard pointer watch.

If a descr is passed then it will internally call descr->on_unwatch.

Parameters
slotthe slot to remove the watch
descrto call on_unwatch on.
static bool tervel::util::memory::hp::HazardPointer::watch ( SlotID  slot_id,
Element elem,
std::atomic< void * > *  address,
void *  expected,
HazardPointer *const  hazard_pointer = tervel::tl_thread_info->get_hazard_pointer() 
)
static

This method is used to achieve a hazard pointer watch on the the based descr.

Internally it will call the descriptors on_watch function.

If after writing descr 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 removes the hazard pointer watch and returns false

Parameters
slotThe position to place the descr value in the watch table.
descrThe descr that is to be watched.
addressThe address to check
expectedThe value which is to be expected at the address
static bool tervel::util::memory::hp::HazardPointer::watch ( SlotID  slot_id,
void *  value,
std::atomic< void * > *  address,
void *  expected,
HazardPointer *const  hazard_pointer = tervel::tl_thread_info->get_hazard_pointer() 
)
static

This method is used to achieve a hazard pointer watch on a memory address.

If after writing the value, it is still at the address (indicated by *a == value), will return true. Otherwise it removes the hazard pointer watch and returns false

Parameters
slotThe position to place the value in the watch table.
valueThe value that is to be watched.
addressThe address to check
expectedThe value which is to be expected at the address
void tervel::util::memory::hp::HazardPointer::watch ( SlotID  slot,
void *  value 
)
inline

This function takes a SlotID and stores the specified value into that the threads alloted slot for that id in the hazard pointer watch list.

Parameters
slotThe id of the slot to watch.
valueThe value to watch

Member Data Documentation

util::memory::hp::ListManager tervel::util::memory::hp::HazardPointer::hp_list_manager_
const size_t tervel::util::memory::hp::HazardPointer::num_slots_
private
std::unique_ptr<std::atomic<void *>[]> tervel::util::memory::hp::HazardPointer::watches_
private

The documentation for this class was generated from the following file: