19 #ifndef UTILS__REFCOUNTEDPOINTER_HPP
20 #define UTILS__REFCOUNTEDPOINTER_HPP
22 #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
26 #include <condition_variable>
74 assert(
nullptr != ptr);
105 , ptr_(parent && parent->is_active_ ? parent->ptr_ : nullptr)
109 parent_->inc_instances();
120 parent_->dec_instances();
137 operator bool()
const
139 return nullptr != ptr_;
147 assert(
nullptr != ptr_);
153 std::shared_ptr<RefCountedPointer<T>> parent_;
162 std::unique_lock<std::mutex> lock(mutex_);
164 cv_.wait(lock, [
this]() ->
bool
166 return instances_ == 0;
177 std::unique_lock<std::mutex> lock(mutex_);
186 std::unique_lock<std::mutex> lock(mutex_);
203 std::atomic<bool> is_active_;
208 mutable std::mutex mutex_;
209 std::condition_variable cv_;
Class to manage the local pointer instance.
Definition: RefCountedPointer.hpp:95
Instance(const Instance &)=delete
T * operator->() const
operator to call the T methods.
Definition: RefCountedPointer.hpp:145
Instance(Instance &&)=default
~Instance()
Destructor.
Definition: RefCountedPointer.hpp:116
Instance(const std::shared_ptr< RefCountedPointer< T >> &parent)
Constructor.
Definition: RefCountedPointer.hpp:102
Instance & operator=(const Instance &)=delete
Class to manage a local pointer with reference counting.
Definition: RefCountedPointer.hpp:56
RefCountedPointer & operator=(const RefCountedPointer &)=delete
~RefCountedPointer()=default
void deactivate()
Ensure no more valid local pointer instances are created, and wait for current ones to die.
Definition: RefCountedPointer.hpp:160
RefCountedPointer(RefCountedPointer &&)=delete
RefCountedPointer(T *ptr)
Explicit constructor.
Definition: RefCountedPointer.hpp:68
RefCountedPointer(const RefCountedPointer &)=delete
eProsima namespace.
Definition: LibrarySettingsAttributes.h:23