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 |
Definition at line 344 of file lockptr.h.
References fawkes::Mutex::NORMAL, and fawkes::Mutex::RECURSIVE.
|
inline |
Copy constructor This increments the shared reference count.
src | refptr to copy |
Definition at line 371 of file lockptr.h.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
inline |
Copy constructor (from different, but castable type).
Increments the reference count.
src | refptr to copy |
Definition at line 389 of file lockptr.h.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
inlineexplicit |
For use only in the internal implementation of LockPtr.
cpp_object | C++ object to wrap |
objmutex | object mutex |
refcount | reference count |
refmutex | reference count mutex |
Definition at line 357 of file lockptr.h.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
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 |
Definition at line 208 of file lockptr.h.
References fawkes::LockPtr< T_CppObject >::refcount_ptr(), and fawkes::LockPtr< T_CppObject >::refmutex_ptr().
|
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 |
Definition at line 168 of file lockptr.h.
References fawkes::LockPtr< T_CppObject >::refcount_ptr(), and fawkes::LockPtr< T_CppObject >::refmutex_ptr().
|
inlinestatic |
Static cast to derived class.
Like the dynamic cast; the notation is
src | source refptr to cast |
Definition at line 190 of file lockptr.h.
References fawkes::LockPtr< T_CppObject >::refcount_ptr(), and fawkes::LockPtr< T_CppObject >::refmutex_ptr().
|
inline |
Set underlying instance to 0, decrementing reference count of existing instance appropriately.
Definition at line 499 of file lockptr.h.
Referenced by CLIPSThread::finalize(), NavGraphThread::finalize(), OpenNiContextThread::finalize(), OpenPRSThread::finalize(), ROSNodeThread::finalize(), and OpenNiContextThread::init().
|
inline |
Lock access to the encapsulated object.
Definition at line 257 of file lockptr.h.
References fawkes::Mutex::lock().
Referenced by ClipsNavGraphThread::clips_context_init(), ClipsRobotMemoryThread::clips_context_init(), ClipsTFThread::clips_context_init(), fawkes::NavGraphGeneratorVoronoi::compute(), FawkesRemotePlexilAdapter::fam_event(), ClipsNavGraphThread::graph_changed(), NavGraphThread::loop(), and OpenNiContextThread::loop().
|
inline |
Get object mutex.
This is the same mutex that is used in the lock(), try_lock(), and unlock() methods.
Definition at line 284 of file lockptr.h.
Referenced by ClipsProtobufThread::clips_context_init(), fawkes::NavGraphGeneratorGrid::compute(), ClipsAgentThread::finalize(), ClipsAgentThread::init(), ClipsExecutiveThread::init(), OpenNiDepthThread::init(), OpenNiHandTrackerThread::init(), OpenNiImageThread::init(), OpenNiPointCloudThread::init(), OpenNiUserTrackerThread::init(), CedarThread::loop(), ClipsAgentThread::loop(), ClipsExecutiveThread::loop(), OpenNiDepthThread::loop(), OpenNiImageThread::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 228 of file lockptr.h.
Referenced by 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 240 of file lockptr.h.
Referenced by fawkes::LockPtr< T_CppObject >::cast_const(), fawkes::LockPtr< T_CppObject >::cast_dynamic(), and fawkes::LockPtr< T_CppObject >::cast_static().
|
inline |
For use only in the internal implementation of sharedptr.
Get reference mutex.
Definition at line 250 of file lockptr.h.
Referenced by fawkes::LockPtr< T_CppObject >::cast_const(), fawkes::LockPtr< T_CppObject >::cast_dynamic(), and fawkes::LockPtr< T_CppObject >::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 407 of file lockptr.h.
Referenced by fawkes::LockPtr< T_CppObject >::swap().
|
inline |
Try to acquire lock for the encapsulated object.
Definition at line 266 of file lockptr.h.
References fawkes::Mutex::try_lock().
|
inline |
Unlock object mutex.
Definition at line 273 of file lockptr.h.
References fawkes::Mutex::unlock().
Referenced by ClipsNavGraphThread::clips_context_init(), ClipsRobotMemoryThread::clips_context_init(), ClipsTFThread::clips_context_init(), fawkes::NavGraphGeneratorVoronoi::compute(), FawkesRemotePlexilAdapter::fam_event(), ClipsNavGraphThread::graph_changed(), NavGraphThread::loop(), and OpenNiContextThread::loop().
|
related |
Swap refptr instances.
lrp | "left" refptr |
rrp | "right" refptr |
Definition at line 512 of file lockptr.h.
References fawkes::LockPtr< T_CppObject >::swap().