Class MultiThreadedRefTracker¶
Defined in File ref_tracker.hpp
Inheritance Relationships¶
Base Type¶
public wrench::RefTracker< MultiThreadedRefTracker >
(Template Class RefTracker)
Class Documentation¶
-
class
wrench
::
MultiThreadedRefTracker
: public wrench::RefTracker<MultiThreadedRefTracker>¶ This type implements a reference tracker which is thread safe and is designed for multi-threaded use. It can be embedded inside a class for intrusive reference tracking.
This implements the RefTracker interface.
Public Types
-
using
Counter
= std::atomic_size_t¶ Defines the type of the counter.
Public Functions
-
MultiThreadedRefTracker
() noexcept¶ Constructor to initialize the reference count.
-
auto add_reference_impl () noexcept -> void
Adds to the reference count.
-
auto release () noexcept -> bool
Decrements the refernce count, and returns true if the resource being tracked with the reference count can be released. If this returns true, then the resource should be deleted by calling
destroy()
.
-
template<typename T, typename Deleter> auto destroy_resource_impl (T *resource, Deleter &&deleter) noexcept -> void
Destroys the resource
resource
, using thedeleter
, which should have a signature of:auto destructor = [] (auto* resource) -> void { // free(resource); }
This creates a thread fence before deleting the resource so that there is a valid release-acquire sequence with
release()
and any access from other threads happens before theis delete.Calling this when
release()
does not returntrue
will invalidate all referenced objects.- Parameters
resource
: The resource to destroy.deleter
: The deleter for the resource.
- Template Parameters
T
: The type of the resource.Deleter
: The type of the deleter.
-
using