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 |
|
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 503 of file lockptr.h.
Referenced by ROSNodeThread::finalize(), OpenNiContextThread::finalize(), CLIPSThread::finalize(), OpenPRSThread::finalize(), NavGraphThread::finalize(), and OpenNiContextThread::init().
|
inline |
Lock access to the encapsulated object.
Definition at line 270 of file lockptr.h.
Referenced by ClipsTFThread::clips_context_init(), ClipsNavGraphThread::clips_context_init(), ClipsRobotMemoryThread::clips_context_init(), fawkes::NavGraphGeneratorVoronoi::compute(), FawkesRemotePlexilAdapter::fam_event(), ClipsNavGraphThread::graph_changed(), fawkes::LockPtr< fawkes::CLIPSEnvManager >::LockPtr(), OpenNiContextThread::loop(), and NavGraphThread::loop().
|
inline |
Get object mutex.
This is the same mutex that is used in the lock(), try_lock(), and unlock() methods.
Definition at line 297 of file lockptr.h.
Referenced by ClipsProtobufThread::clips_context_init(), fawkes::NavGraphGeneratorGrid::compute(), ClipsAgentThread::finalize(), ClipsExecutiveThread::init(), OpenNiHandTrackerThread::init(), ClipsAgentThread::init(), OpenNiDepthThread::init(), OpenNiImageThread::init(), OpenNiUserTrackerThread::init(), OpenNiPointCloudThread::init(), CedarThread::loop(), ClipsExecutiveThread::loop(), ClipsAgentThread::loop(), OpenNiImageThread::loop(), OpenNiDepthThread::loop(), and OpenNiPointCloudThread::loop().
|
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 241 of file lockptr.h.
Referenced by OpenNiContextThread::init(), and OpenNiContextThread::loop().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Unlock object mutex.
Definition at line 286 of file lockptr.h.
Referenced by ClipsTFThread::clips_context_init(), ClipsNavGraphThread::clips_context_init(), ClipsRobotMemoryThread::clips_context_init(), fawkes::NavGraphGeneratorVoronoi::compute(), FawkesRemotePlexilAdapter::fam_event(), ClipsNavGraphThread::graph_changed(), OpenNiContextThread::loop(), and NavGraphThread::loop().
|
related |
Swap refptr instances.
lrp | "left" refptr |
rrp | "right" refptr |
Definition at line 516 of file lockptr.h.
Referenced by fawkes::RefPtr< Roomba500 >::clear(), fawkes::RefPtr< Roomba500 >::operator bool(), fawkes::LockPtr< fawkes::CLIPSEnvManager >::operator bool(), fawkes::RefPtr< Roomba500 >::operator=(), and fawkes::LockPtr< fawkes::CLIPSEnvManager >::operator=().