Zero  0.1.0
Public Member Functions | Protected Attributes | List of all members
GcPointer< T > Class Template Reference

Wrapper for gc_pointer_raw. More...

#include <w_gc_pool_forest.h>

Public Member Functions

 GcPointer ()
 
 GcPointer (gc_pointer_raw raw)
 
 GcPointer (const GcPointer &other)
 
GcPointeroperator= (const GcPointer &other)
 
bool operator== (const GcPointer &other) const
 
bool operator!= (const GcPointer &other) const
 
bool is_equal_address (const GcPointer &other) const
 
Tdereference (GcPoolForest< T > &pool) const
 
void set_mark (bool on)
 
bool is_marked () const
 
gc_aba get_aba () const
 
void set_aba (gc_aba stamp)
 
gc_generation get_generation () const
 
gc_segment get_segment () const
 
gc_offset get_offset () const
 
bool is_null () const
 
gc_pointer_rawraw ()
 
gc_pointer_raw raw () const
 
bool atomic_cas (const GcPointer &expected, const GcPointer &desired)
 [Atomic] Compare and set for pointer, mark, and ABA counter altogether. See Figure 9.23 of [HERLIHY] More...
 
GcPointer atomic_swap (const GcPointer &new_ptr)
 [Atomic] Atomic swap. More...
 

Protected Attributes

gc_pointer_raw _raw
 

Detailed Description

template<class T>
class GcPointer< T >

Wrapper for gc_pointer_raw.

Template Parameters
TType of the pointed class/struct.

Atomic Functions and Non-Atomic Functions

Methods whose name start with "atomic_" provide atomic semantics. Other method are NOT atomic. So, appropriately use memory barriers to protect your access. However, other methods are regular, meaning you will not see an utter garbage but only see either the old value or new value (some valid value other thread set). This is possible because this class contains only 8 bytes information. In x86_64, an aligned 8 byte access is always regular though not atomic.

When you want to call more than one non-atomic methods of GcPointer, it's a good idea to copy a shared GcPointer variable to a local GcPointer variable then access the local one. For example,

// This might be bad! (unless only used as inputs for atomic_cas)
bool marked = some_shared_gc_pointer.is_marked();
... many lines in-between
gc_aba stamp = some_shared_gc_pointer.get_aba();
// This is at least regular.
GcPointer<Hoge> copied(some_shared_gc_pointer);
bool marked = copied.is_marked();
... many lines in-between
gc_aba stamp = copied.get_aba();

The copy/assignment operators of this class use the ACCESS_ONCE semantics to prohibit compiler from doing something dangerous for this purpose.

Still, CPU might do something and this is not atomic either. In case it matters, use the atomic_cas() or atomic_swap().

Constructor & Destructor Documentation

§ GcPointer() [1/3]

template<class T>
GcPointer< T >::GcPointer ( )
inline

Empty NULL constructor.

§ GcPointer() [2/3]

template<class T>
GcPointer< T >::GcPointer ( gc_pointer_raw  raw)
inlineexplicit

Constructs with gc_pointer_raw.

§ GcPointer() [3/3]

template<class T>
GcPointer< T >::GcPointer ( const GcPointer< T > &  other)
inline

Copy constructor. This is regular though might not be atomic.

Member Function Documentation

§ atomic_cas()

template<class T>
bool GcPointer< T >::atomic_cas ( const GcPointer< T > &  expected,
const GcPointer< T > &  desired 
)
inline

[Atomic] Compare and set for pointer, mark, and ABA counter altogether. See Figure 9.23 of [HERLIHY]

Parameters
[in]expectedtest value
[in]desiredif succeeds this value is set
Returns
whether the CAS succeeds.

§ atomic_swap()

template<class T>
GcPointer GcPointer< T >::atomic_swap ( const GcPointer< T > &  new_ptr)
inline

[Atomic] Atomic swap.

Parameters
[in]new_ptrthe value to set
Returns
old value before swap

§ dereference()

template<class T >
T * GcPointer< T >::dereference ( GcPoolForest< T > &  pool) const
inline

De-references the pointer to return the actual object.

§ get_aba()

template<class T>
gc_aba GcPointer< T >::get_aba ( ) const
inline

[Non-atomic] Returns the ABA counter.

§ get_generation()

template<class T>
gc_generation GcPointer< T >::get_generation ( ) const
inline

[Non-atomic] Returns generation.

§ get_offset()

template<class T>
gc_offset GcPointer< T >::get_offset ( ) const
inline

[Non-atomic] Returns offset.

§ get_segment()

template<class T>
gc_segment GcPointer< T >::get_segment ( ) const
inline

[Non-atomic] Returns segment.

§ is_equal_address()

template<class T>
bool GcPointer< T >::is_equal_address ( const GcPointer< T > &  other) const
inline

[Non-atomic] Equality operator that compares only the address part without ABA counter and mark.

§ is_marked()

template<class T>
bool GcPointer< T >::is_marked ( ) const
inline

[Non-atomic] Returns if the pointer is marked in the stashed boolen flag.

§ is_null()

template<class T>
bool GcPointer< T >::is_null ( ) const
inline

[Non-atomic] Tells if the pointer is null.

§ operator!=()

template<class T>
bool GcPointer< T >::operator!= ( const GcPointer< T > &  other) const
inline

[Non-atomic] Inequality operator on the contained pointer value.

§ operator=()

template<class T>
GcPointer& GcPointer< T >::operator= ( const GcPointer< T > &  other)
inline

Copy assignment. This is regular though might not be atomic.

§ operator==()

template<class T>
bool GcPointer< T >::operator== ( const GcPointer< T > &  other) const
inline

[Non-atomic] Equality operator on the contained pointer value.

§ raw() [1/2]

template<class T>
gc_pointer_raw& GcPointer< T >::raw ( )
inline

[Non-atomic] Returns single integer representation.

§ raw() [2/2]

template<class T>
gc_pointer_raw GcPointer< T >::raw ( ) const
inline

[Non-atomic] Returns single integer representation.

§ set_aba()

template<class T>
void GcPointer< T >::set_aba ( gc_aba  stamp)
inline

[Non-atomic] Sets the ABA counter.

§ set_mark()

template<class T>
void GcPointer< T >::set_mark ( bool  on)
inline

[Non-atomic] Marks the pointer for death, stashing TRUE into the pointer.

See also
atomic_cas()

Member Data Documentation

§ _raw

template<class T>
gc_pointer_raw GcPointer< T >::_raw
protected

The pointer and stashed flags.


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