Fawkes API
Fawkes Development Version
|
LockPtr<> is a reference-counting shared lockable smartpointer. More...
#include <lockptr.h>
Public Member Functions | |
LockPtr () | |
Default constructor. More... | |
~LockPtr () | |
Destructor - decrements reference count. More... | |
LockPtr (T_CppObject *cpp_object, bool recursive_mutex=false) | |
Constructor that takes ownership. More... | |
LockPtr (const LockPtr< T_CppObject > &src) | |
Copy constructor This increments the shared reference count. More... | |
template<class T_CastFrom > | |
LockPtr (const LockPtr< T_CastFrom > &src) | |
Copy constructor (from different, but castable type). More... | |
void | swap (LockPtr< T_CppObject > &other) |
Swap the contents of two LockPtr<>. More... | |
LockPtr< T_CppObject > & | operator= (const LockPtr< T_CppObject > &src) |
Copy from another LockPtr. More... | |
template<class T_CastFrom > | |
LockPtr< T_CppObject > & | operator= (const LockPtr< T_CastFrom > &src) |
Copy from different, but castable type). More... | |
LockPtr< T_CppObject > & | operator= (T_CppObject *ptr) |
Assign object and claim ownership. More... | |
bool | operator== (const LockPtr< T_CppObject > &src) const |
Tests whether the LockPtr<> point to the same underlying instance. More... | |
bool | operator!= (const LockPtr< T_CppObject > &src) const |
Tests whether the LockPtr<> do not point to the same underlying instance. More... | |
T_CppObject * | operator-> () const |
Dereferencing. More... | |
T_CppObject * | operator* () const |
Get underlying pointer. More... | |
operator bool () const | |
Test whether the LockPtr<> points to any underlying instance. More... | |
void | clear () |
Set underlying instance to 0, decrementing reference count of existing instance appropriately. More... | |
LockPtr (T_CppObject *cpp_object, Mutex *objmutex, int *refcount, Mutex *refmutex) | |
For use only in the internal implementation of LockPtr. More... | |
int | refcount () const |
Get current refcount. More... | |
int * | refcount_ptr () const |
For use only in the internal implementation of sharedptr. More... | |
Mutex * | refmutex_ptr () const |
For use only in the internal implementation of sharedptr. More... | |
void | lock () const |
Lock access to the encapsulated object. More... | |
bool | try_lock () const |
Try to acquire lock for the encapsulated object. More... | |
void | unlock () const |
Unlock object mutex. More... | |
Mutex * | objmutex_ptr () const |
Get object mutex. More... | |
Static Public Member Functions | |
template<class T_CastFrom > | |
static LockPtr< T_CppObject > | cast_dynamic (const LockPtr< T_CastFrom > &src) |
Dynamic cast to derived class. More... | |
template<class T_CastFrom > | |
static LockPtr< T_CppObject > | cast_static (const LockPtr< T_CastFrom > &src) |
Static cast to derived class. More... | |
template<class T_CastFrom > | |
static LockPtr< T_CppObject > | cast_const (const LockPtr< T_CastFrom > &src) |
Cast to non-const. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T_CppObject > | |
void | swap (LockPtr< T_CppObject > &lrp, LockPtr< T_CppObject > &rrp) |
Swap refptr instances. More... | |
LockPtr<> is a reference-counting shared lockable smartpointer.
Reference counting means that a shared reference count is incremented each time a LockPtr is copied, and decremented each time a LockPtr is destroyed, for instance when it leaves its scope. When the reference count reaches zero, the contained object is deleted
Fawkes uses LockPtr so that you don't need to remember to delete the object explicitly, or know when a method expects you to delete the object that it returns.
It is similar to RefPtr, but additionally it provides one shared lock which can be used to coordinate locking for the encapsulated object.
Note that LockPtr is thread-safe, but that you need to handle locking and unlocking for the shared resource yourself!
|
inline |
Default constructor.
Afterwards it will be null and use of -> will cause a segmentation fault.
Definition at line 288 of file lockptr.h.
Referenced by fawkes::LockPtr< fawkes::CLIPSEnvManager >::cast_const().
|
inline |
|
inlineexplicit |
Constructor that takes ownership.
This takes ownership of cpp_object, so it will be deleted when the last LockPtr is deleted, for instance when it goes out of scope.
cpp_object | C++ object to take ownership of |
recursive_mutex | true to create a recursive mutex (with deadlock prevention when locked from the same thread) for the object mutex, false to create a normal mutex |
|
inline |
|
inline |
|
inlineexplicit |
|
inlinestatic |
Cast to non-const.
The LockPtr can't be cast with the usual notation so instead you can use
src | source refptr to cast |
|
inlinestatic |
Dynamic cast to derived class.
The LockPtr can't be cast with the usual notation so instead you can use
src | source refptr to cast |
|
inlinestatic |
Static cast to derived class.
Like the dynamic cast; the notation is
src | source refptr to cast |
|
inline |
Set underlying instance to 0, decrementing reference count of existing instance appropriately.
Definition at line 492 of file lockptr.h.
Referenced by ROSNodeThread::finalize(), OpenNiContextThread::finalize(), CLIPSThread::finalize(), OpenPRSThread::finalize(), NavGraphThread::finalize(), OpenNiContextThread::init(), fawkes::CLIPSAspect::~CLIPSAspect(), and fawkes::ROSAspect::~ROSAspect().
|
inline |
Lock access to the encapsulated object.
Definition at line 247 of file lockptr.h.
Referenced by ClipsTFThread::clips_context_init(), ClipsNavGraphThread::clips_context_init(), fawkes::NavGraphGeneratorVoronoi::compute(), ClipsNavGraphThread::graph_changed(), NavGraphVisualizationThread::loop(), OpenNiContextThread::loop(), NavGraphThread::loop(), and fawkes::LockPtr< fawkes::CLIPSEnvManager >::~LockPtr().
|
inline |
Get object mutex.
This is the same mutex that is used in the lock(), try_lock(), and unlock() methods.
Definition at line 262 of file lockptr.h.
Referenced by BlackboardCLIPSFeature::clips_context_destroyed(), ClipsProtobufThread::clips_context_init(), ClipsAgentThread::finalize(), OpenNiHandTrackerThread::init(), ClipsAgentThread::init(), OpenNiDepthThread::init(), OpenNiImageThread::init(), OpenNiUserTrackerThread::init(), OpenNiPointCloudThread::init(), ClipsROSThread::loop(), ClipsAgentThread::loop(), OpenNiImageThread::loop(), OpenNiDepthThread::loop(), OpenNiPointCloudThread::loop(), and ClipsWebRequestProcessor::process_request().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Get current refcount.
Get reference count. Use this with care, as it may change any time.
Definition at line 229 of file lockptr.h.
Referenced by fawkes::LockPtr< fawkes::CLIPSEnvManager >::cast_const(), OpenNiContextThread::init(), and OpenNiContextThread::loop().
|
inline |
For use only in the internal implementation of sharedptr.
Get reference count pointer. Warning: This is for internal use only. Do not manually modify the reference count with this pointer.
Definition at line 237 of file lockptr.h.
Referenced by fawkes::LockPtr< fawkes::CLIPSEnvManager >::cast_const(), fawkes::LockPtr< fawkes::CLIPSEnvManager >::cast_dynamic(), and fawkes::LockPtr< fawkes::CLIPSEnvManager >::cast_static().
|
inline |
For use only in the internal implementation of sharedptr.
Get reference mutex.
Definition at line 243 of file lockptr.h.
Referenced by fawkes::LockPtr< fawkes::CLIPSEnvManager >::cast_const(), fawkes::LockPtr< fawkes::CLIPSEnvManager >::cast_dynamic(), and fawkes::LockPtr< fawkes::CLIPSEnvManager >::cast_static().
|
inline |
Swap the contents of two LockPtr<>.
This method swaps the internal pointers to T_CppObject. This can be done safely without involving a reference/unreference cycle and is therefore highly efficient.
other | other instance to swap with. |
Definition at line 399 of file lockptr.h.
Referenced by fawkes::LockPtr< fawkes::CLIPSEnvManager >::swap().
|
inline |
|
inline |
Unlock object mutex.
Definition at line 255 of file lockptr.h.
Referenced by ClipsTFThread::clips_context_init(), ClipsNavGraphThread::clips_context_init(), fawkes::NavGraphGeneratorVoronoi::compute(), ClipsNavGraphThread::graph_changed(), NavGraphVisualizationThread::loop(), OpenNiContextThread::loop(), and NavGraphThread::loop().