Broom 1.0.0
A thread-local C++ Garbage Collector
Loading...
Searching...
No Matches
api.cc
Go to the documentation of this file.
1#include "include/broom.h"
2#include "src/allocator.h"
4
5namespace broom {
6thread_local GarbageCollector* t_gc = nullptr;
8 BENSURE_EQ(t_gc, nullptr, "Garbage collector state already initialized.");
10 BENSURE_NE(t_gc, nullptr, "Garbage collector could not be initialized.");
11}
13 BENSURE_NE(t_gc, nullptr,
14 "Attempting to delete an uninitialized garbage collector state");
15 delete t_gc;
16 t_gc = nullptr;
17}
18
19#ifdef BROOM_FOR_TESTING
20GarbageCollector* thread_get_gc() { return t_gc; }
21#endif
22
38
47
49 : gc_(gc), precise_root_ref_(gc_->RegisterPreciseRoot(PreciseRoot(this))) {}
52BroomValue::~BroomValue() { gc_->UnregisterPreciseRoot(precise_root_ref_); }
53
55 if (this == &other) return *this;
56 BENSURE(gc_ == other.gc_, "Expected the garbage collector pointers");
57 BASSERT_NE(precise_root_ref_, nullptr,
58 "Expected a valid precise root reference");
59 gc_->UnregisterPreciseRoot(precise_root_ref_);
60 precise_root_ref_ = gc_->RegisterPreciseRoot(PreciseRoot(this));
61 return *this;
62}
63
65 if (this == &other) return *this;
66 BENSURE(gc_ == other.gc_, "Expected the garbage collector pointers");
67 gc_->UnregisterPreciseRoot(precise_root_ref_);
68 BASSERT_NE(precise_root_ref_, nullptr,
69 "Expected a valid precise root reference");
70 precise_root_ref_ = gc_->RegisterPreciseRoot(PreciseRoot(this));
71 return *this;
72}
73} // namespace broom
BroomValue & operator=(const BroomValue &other)
Definition api.cc:54
virtual ~BroomValue()
Definition api.cc:52
BROOM_INLINE void RegisterExternalRoot(ExternalRoot root)
BROOM_INLINE void RegisterPointer(const void *pointer, Destructor destructor=nullptr)
void * AllocateRawDontRegister(size_t size)
BROOM_INLINE void EnableAutomatedCollection()
BROOM_INLINE void UnregisterExternalRoot(ExternalRoot root)
BROOM_INLINE void DisableAutomatedCollection()
BROOM_INLINE void * RegisterPreciseRoot(PreciseRoot root)
BROOM_INLINE void Pin(const void *pointer, uint32_t how_many=1)
BROOM_INLINE void UnregisterPreciseRoot(void *type_erased_root)
#define BENSURE(x, m,...)
Definition macros.h:22
#define BASSERT_NE(lhs, rhs, m,...)
Definition macros.h:63
#define BENSURE_NE(lhs, rhs, m,...)
Definition macros.h:36
#define BENSURE_EQ(lhs, rhs, m,...)
Definition macros.h:26
void RegisterWithGc(const void *pointer, Destructor destructor)
Definition api.cc:25
void TurnOnGarbageCollection()
Definition api.cc:36
void * AllocateRaw(size_t size)
Definition api.cc:24
void TurnOffGarbageCollection()
Definition api.cc:35
void ShareRaw(const void *pointer, uint32_t how_many)
Definition api.cc:28
void UnpinPointer(GarbageCollector *gc, const void *pointer)
Definition api.cc:31
GarbageCollector * GetGarbageCollector()
Definition api.cc:34
std::add_pointer< void(const void *)>::type Destructor
Definition broom.h:245
thread_local GarbageCollector * t_gc
Definition api.cc:6
void unregister_external(const void *pointer)
Definition api.cc:44
void thread_init(broom_configuration config)
Definition api.cc:7
void thread_teardown()
Definition api.cc:12
void force_collection()
Definition api.cc:39
std::queue< T, broom::deque< T > > queue
Definition broom-queue.h:12
void register_external(const void *pointer, size_t size)
Definition api.cc:41
void force_slow_collection()
Definition api.cc:40