|
Broom 1.0.0
A thread-local C++ Garbage Collector
|
#include <broom.h>
Public Member Functions | |
| BroomSharingPointer ()=delete | |
| BroomSharingPointer (const BroomSharingPointer &other) | |
| ~BroomSharingPointer ()=default | |
| BroomSharingPointer & | operator= (const BroomSharingPointer &other)=delete |
| BroomSharingPointer & | operator= (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 > |
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.
|
delete |
|
inline |
The copy constructor for BroomSharingPointer. This is defined to support usage in containers (in particular, STL containers).
| other | The BroomSharingPointer object to copy. |
|
default |
Default destructor.
|
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.
|
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().
| ptr | The raw pointer to share. |
| how_many | The count describing how many times the BroomSharingPointer must be disposed for the garbage collector to unpin the allocation. |
|
inline |
A helper operator*() to support usage such as:
|
inline |
A helper operator->() to support usage such as:
|
deletenoexcept |
|
delete |
|
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.
|
friend |