Broom 1.0.0
A thread-local C++ Garbage Collector
Loading...
Searching...
No Matches
Public Member Functions | List of all members
broom::BroomLifetimeAnchor< T > Class Template Reference

#include <broom.h>

Public Member Functions

 BroomLifetimeAnchor (BroomSharingPointer< T > ptr)
 
 ~BroomLifetimeAnchor ()
 
T * to_unsafe_ptr () const
 
T * operator-> ()
 
T & operator* ()
 

Detailed Description

template<typename T>
class broom::BroomLifetimeAnchor< T >

BroomLifetimeAnchor encapsulates the notion of a lifetime of a BroomSharingPointer. When a managed pointer is shared between threads, the threads which do not own the managed pointer must anchor its lifetime at some point during their use of said pointer. Failing to do so will result in a pinned allocation that cannot be garbage collected. The number of BroomLifetimeAnchor usages must match the number of times the pointer was shared using broom::share().

*
*   Thread 1:
*     ...
*     queue.push(broom::share<T>(broom::allocate<T>(...)));
*     ...
*
*   Thread 2:
*     ...
*     {
*       ...
*       broom::lifetime_anchor<T> value = queue.front();
*       queue.pop();
*       ...
*     } <- broom::lifetime_anchor<T> is destroyed
*     ^
*       Usage of any broom::sharing_ptr<T> below here may be unsafe depending
*       on the integer argument during initialization.
*     ...
* 

lifetime_anchor is also available as a type alias for this class to support a more traditional C++ style.

Definition at line 631 of file broom.h.

Constructor & Destructor Documentation

◆ BroomLifetimeAnchor()

template<typename T >
broom::BroomLifetimeAnchor< T >::BroomLifetimeAnchor ( BroomSharingPointer< T >  ptr)
inline

An implicit constructor for BroomLifetimeAnchor to easily create anchors and support code such as:

std::queue< T, broom::deque< T > > queue
Definition broom-queue.h:12
Parameters
ptrThe BroomSharingPointer to anchor the lifetime of.

Definition at line 642 of file broom.h.

◆ ~BroomLifetimeAnchor()

Calls the BroomSharingPointer::dispose() method.

Definition at line 646 of file broom.h.

Member Function Documentation

◆ operator*()

template<typename T >
T & broom::BroomLifetimeAnchor< T >::operator* ( )
inline

A helper operator*() to support usage such as:

Definition at line 667 of file broom.h.

◆ operator->()

template<typename T >
T * broom::BroomLifetimeAnchor< T >::operator-> ( )
inline

A helper operator->() to support usage such as:

p->foo();

Definition at line 659 of file broom.h.

◆ to_unsafe_ptr()

template<typename T >
T * broom::BroomLifetimeAnchor< T >::to_unsafe_ptr ( ) const
inline

Returns a raw managed pointer encapsulated by the BroomLifetimeAnchor.

Definition at line 651 of file broom.h.


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