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

#include <broom.h>

Public Member Functions

 BroomSharingPointer ()=delete
 
 BroomSharingPointer (const BroomSharingPointer &other)
 
 ~BroomSharingPointer ()=default
 
BroomSharingPointeroperator= (const BroomSharingPointer &other)=delete
 
BroomSharingPointeroperator= (const BroomSharingPointer &&other) noexcept=delete
 
T * to_unsafe_ptr () const
 
T * operator-> ()
 
T & operator* ()
 
void dispose () const
 

Static Public Member Functions

static constexpr BroomSharingPointer make (T *ptr, uint32_t how_many)
 

Friends

class BroomLifetimeAnchor< T >
 

Detailed Description

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

BroomSharingPointer is one part of an implementation for controlled sharing of managed (garbage collected) pointers across threads. Since Broom's garbage collector state is per-thread and never pauses other threads, BroomSharingPointer guarantees that any managed pointer that has been shared is never garbage collected until its corresponding BroomLiftimeAnchor is destroyed. BroomSharingPointer is constructed with an appropriate integer argument, defaulting to 1, stating how many times a corresponding BroomLifetimeAnchor must be destroyed before the pointer is garbage collected. BroomSharingPointer is not meant to be constructed directly. Instead, use the broom::share() helper function to do so. A simple example of BroomSharingPointer usage using a std::queue using the more standard C++ style:

*   T1:
*     ...
*     queue.push(broom::share<T>(broom::allocate<T>(...)));
*     ...
*
*   T2:
*     ...
*     {
*       ...
*       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.
*     ...
* 

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

Definition at line 507 of file broom.h.

Constructor & Destructor Documentation

◆ BroomSharingPointer() [1/2]

template<typename T >
broom::BroomSharingPointer< T >::BroomSharingPointer ( )
delete

◆ BroomSharingPointer() [2/2]

template<typename T >
broom::BroomSharingPointer< T >::BroomSharingPointer ( const BroomSharingPointer< T > &  other)
inline

The copy constructor for BroomSharingPointer. This is defined to support usage in containers (in particular, STL containers).

Parameters
otherThe BroomSharingPointer object to copy.

Definition at line 516 of file broom.h.

◆ ~BroomSharingPointer()

template<typename T >
broom::BroomSharingPointer< T >::~BroomSharingPointer ( )
default

Default destructor.

Member Function Documentation

◆ dispose()

template<typename T >
void broom::BroomSharingPointer< T >::dispose ( ) const
inline

Safely notifies the garbage collector of the thread that owns the managed pointer encapsulated by this object that the current thread is done using it. This method shouldn't be directly used if at all possible, and instead you should try to structure the code to use BroomLifetimeAnchor.

Definition at line 575 of file broom.h.

◆ make()

template<typename T >
static constexpr BroomSharingPointer broom::BroomSharingPointer< T >::make ( T *  ptr,
uint32_t  how_many 
)
inlinestaticconstexpr

A static helper which has access to private members. Called by broom::share() to construct a BroomSharingPointer. This static method is not meant to be used directly. Instead, use broom::share().

Parameters
ptrThe raw pointer to share.
how_manyThe count describing how many times the BroomSharingPointer must be disposed for the garbage collector to unpin the allocation.
Returns
A BroomSharingPointer which is safe to be used by other threads.

Definition at line 563 of file broom.h.

◆ operator*()

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

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

foo(*p);
std::queue< T, broom::deque< T > > queue
Definition broom-queue.h:12

Definition at line 549 of file broom.h.

◆ operator->()

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

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

p->foo();

Definition at line 541 of file broom.h.

◆ operator=() [1/2]

template<typename T >
BroomSharingPointer & broom::BroomSharingPointer< T >::operator= ( const BroomSharingPointer< T > &&  other)
deletenoexcept

◆ operator=() [2/2]

◆ to_unsafe_ptr()

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

Returns the raw pointer from a BroomSharingPointer. This should only be used in contexts where you can guarantee the lifetime of the BroomSharingPointer to persist at least as long as the lifetime of the raw pointer.

Definition at line 533 of file broom.h.

Friends And Related Symbol Documentation

◆ BroomLifetimeAnchor< T >

template<typename T >
friend class BroomLifetimeAnchor< T >
friend

Definition at line 594 of file broom.h.


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