Zero  0.1.0
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
GcPoolForest< T > Struct Template Reference

Garbage-collected Pool Forest. More...

#include <w_gc_pool_forest.h>

Public Member Functions

 GcPoolForest (const char *debug_name, uint32_t desired_gens, size_t initial_segment_count, gc_offset initial_segment_size)
 
 ~GcPoolForest ()
 
Tresolve_pointer (const GcPointer< T > &pointer)
 
Tresolve_pointer (gc_pointer_raw pointer)
 
GcGeneration< T > * resolve_generation (gc_pointer_raw pointer)
 
GcGeneration< T > * resolve_generation (gc_generation gen)
 
GcSegment< T > * resolve_segment (gc_pointer_raw pointer)
 
GcSegment< T > * resolve_segment (gc_generation gen, gc_segment seg)
 
Tallocate (gc_pointer_raw &next, gc_thread_id self)
 
void deallocate (T *pointer)
 
void deallocate (gc_pointer_raw pointer)
 
gc_pointer_raw occupy_segment (gc_thread_id self)
 
gc_generation head () const
 
gc_generation tail () const
 
gc_generation curr () const
 
size_t active_generations () const
 
GcGeneration< T > * head_generation ()
 
GcGeneration< T > * curr_generation ()
 
bool is_valid_generation (gc_generation generation) const
 
bool advance_generation (lsn_t low_water_mark, lsn_t now, size_t initial_segment_count, gc_offset segment_size)
 
void retire_generations (lsn_t low_water_mark, lsn_t recycle_now=lsn_t::null)
 
void mfence () const
 

Static Public Member Functions

static gc_generation wrap (size_t i)
 

Public Attributes

const char * name
 
uint32_t head_nowrap
 
uint32_t curr_nowrap
 
uint32_t tail_nowrap
 
uint32_t desired_generations
 
GcGeneration< T > * generations [GC_MAX_GENERATIONS]
 
lsn_t epochs [GC_MAX_GENERATIONS]
 
GcWakeupFunctorgc_wakeup_functor
 

Detailed Description

template<class T>
struct GcPoolForest< T >

Garbage-collected Pool Forest.

Template Parameters
TType of the managed class/struct. It must have a member "gc_pointer_raw gc_pointer" accessible to this class.

This is a Roll-Your-Own Garbage Collector implementation optimized for long-running services such as filesystems and databases.

Constructor & Destructor Documentation

§ GcPoolForest()

template<class T>
GcPoolForest< T >::GcPoolForest ( const char *  debug_name,
uint32_t  desired_gens,
size_t  initial_segment_count,
gc_offset  initial_segment_size 
)
inline

§ ~GcPoolForest()

template<class T>
GcPoolForest< T >::~GcPoolForest ( )
inline

Member Function Documentation

§ active_generations()

template<class T>
size_t GcPoolForest< T >::active_generations ( ) const
inline

Returns the number of active generations.

§ advance_generation()

template<class T >
bool GcPoolForest< T >::advance_generation ( lsn_t  low_water_mark,
lsn_t  now,
size_t  initial_segment_count,
gc_offset  segment_size 
)
inline

Create a new generation for the given starting LSN.

Parameters
[in]low_water_markLSN of the oldest transaction in the system. Used to recycle old generations. lsn_t::null prohibits recycling.
[in]nowhigest LSN as of now, which means every thread that newly allocates from this new generation would have this LSN or higher.
Returns
whether we could advance the generation or there is already a generation for the starting LSN (or more recent). false means too many generations.

§ allocate()

template<class T >
T * GcPoolForest< T >::allocate ( gc_pointer_raw next,
gc_thread_id  self 
)
inline

Allocate a new object from this pool.

Parameters
[in,out]nextthis is a thread-local hint to allocate from. we also increment or even switch to new segment. the caller probably uses a thread-local for this.
[in]selfSome ID of the calling thread. eg, pthread_self().

§ curr()

template<class T>
gc_generation GcPoolForest< T >::curr ( ) const
inline

The yougnest active generation in which we should allocate new segments. wrapped.

§ curr_generation()

template<class T>
GcGeneration<T>* GcPoolForest< T >::curr_generation ( )
inline

§ deallocate() [1/2]

template<class T>
void GcPoolForest< T >::deallocate ( T pointer)
inline

Return an object to this pool.

Parameters
[in]pointerThe object to return.

§ deallocate() [2/2]

template<class T>
void GcPoolForest< T >::deallocate ( gc_pointer_raw  pointer)
inline

Return an object to this pool.

Parameters
[in]pointerLogical pointer to the object to return.

§ head()

template<class T>
gc_generation GcPoolForest< T >::head ( ) const
inline

The oldest active generation. wrapped.

§ head_generation()

template<class T>
GcGeneration<T>* GcPoolForest< T >::head_generation ( )
inline

§ is_valid_generation()

template<class T>
bool GcPoolForest< T >::is_valid_generation ( gc_generation  generation) const
inline

§ mfence()

template<class T>
void GcPoolForest< T >::mfence ( ) const
inline

full load-store fence.

§ occupy_segment()

template<class T >
gc_pointer_raw GcPoolForest< T >::occupy_segment ( gc_thread_id  self)
inline

Occupy a segment in latest generation and return a pointer to its first object.

§ resolve_generation() [1/2]

template<class T>
GcGeneration<T>* GcPoolForest< T >::resolve_generation ( gc_pointer_raw  pointer)
inline

§ resolve_generation() [2/2]

template<class T>
GcGeneration<T>* GcPoolForest< T >::resolve_generation ( gc_generation  gen)
inline

§ resolve_pointer() [1/2]

template<class T>
T* GcPoolForest< T >::resolve_pointer ( const GcPointer< T > &  pointer)
inline

Returns a physical pointer represented by the logical pointer.

§ resolve_pointer() [2/2]

template<class T>
T * GcPoolForest< T >::resolve_pointer ( gc_pointer_raw  pointer)
inline

Returns a physical pointer represented by the logical pointer.

§ resolve_segment() [1/2]

template<class T>
GcSegment<T>* GcPoolForest< T >::resolve_segment ( gc_pointer_raw  pointer)
inline

§ resolve_segment() [2/2]

template<class T>
GcSegment<T>* GcPoolForest< T >::resolve_segment ( gc_generation  gen,
gc_segment  seg 
)
inline

§ retire_generations()

template<class T >
void GcPoolForest< T >::retire_generations ( lsn_t  low_water_mark,
lsn_t  recycle_now = lsn_t::null 
)
inline

Retire old generations that are no longer needed.

Parameters
[in]low_water_markLSN of the oldest transaction in the system
[in]recycle_nowhigest LSN as of now. This is used to recycle retired generations. lsn_t::null means prohibiting recycle.

§ tail()

template<class T>
gc_generation GcPoolForest< T >::tail ( ) const
inline

The exclusive end of active generations. wrapped.

§ wrap()

template<class T>
static gc_generation GcPoolForest< T >::wrap ( size_t  i)
inlinestatic

Member Data Documentation

§ curr_nowrap

template<class T>
uint32_t GcPoolForest< T >::curr_nowrap

The latest active generation. No wrap, so take modulo before use.

§ desired_generations

template<class T>
uint32_t GcPoolForest< T >::desired_generations

Desired number of generations. Don't add more than it unless can't retire old ones.

§ epochs

template<class T>
lsn_t GcPoolForest< T >::epochs[GC_MAX_GENERATIONS]

LSN as of starting each generation.

§ gc_wakeup_functor

template<class T>
GcWakeupFunctor* GcPoolForest< T >::gc_wakeup_functor

Function pointer to wakeup GC when pre-allocation or retiring gets behind.

§ generations

template<class T>
GcGeneration<T>* GcPoolForest< T >::generations[GC_MAX_GENERATIONS]

Active (or being-retired) generation objects.

§ head_nowrap

template<class T>
uint32_t GcPoolForest< T >::head_nowrap

The oldest active generation. No wrap, so take modulo before use.

§ name

template<class T>
const char* GcPoolForest< T >::name

Only used to put the name of this forest in debug print.

§ tail_nowrap

template<class T>
uint32_t GcPoolForest< T >::tail_nowrap

The exclusive end of active generation. No wrap, so take modulo before use.


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