Fawkes API  Fawkes Development Version
fawkes::RefCount Class Reference

Reference counting base class. More...

#include <core/utils/refcount.h>

Inheritance diagram for fawkes::RefCount:

Public Member Functions

 RefCount ()
 Constructor. More...
 
virtual ~RefCount ()
 Destructor. More...
 
void ref ()
 Increment reference count. More...
 
void unref ()
 Decrement reference count and conditionally delete this instance. More...
 
unsigned int refcount ()
 Get reference count for this instance. More...
 

Detailed Description

Reference counting base class.

Derive this class with your object if you need reference counting for the object thus that it is not deleted while some code is still using an class instance.

The RefCount class is NOT meant for direct usage. In most cases if you are aware of the need of reference couting during the design of the software derive this class. This is the recommended way. If you want to use reference counting with a class that you cannot or do not want to modify you can use the RefCounter template class to accomplish the desired task.

See also
RefCounter
Author
Tim Niemueller

Definition at line 32 of file refcount.h.

Constructor & Destructor Documentation

◆ RefCount()

fawkes::RefCount::RefCount ( )

Constructor.

Definition at line 50 of file refcount.cpp.

◆ ~RefCount()

fawkes::RefCount::~RefCount ( )
virtual

Destructor.

Definition at line 58 of file refcount.cpp.

Member Function Documentation

◆ ref()

◆ refcount()

unsigned int fawkes::RefCount::refcount ( )

Get reference count for this instance.

The reference count is used to determine if a message should really be destructed or not. Do not rely on this value, as race-conditions may ruin your code! Do only use the atomic ref() and unref() operations. This function is only provided to output informational debugging output!

Returns
reference count

Definition at line 125 of file refcount.cpp.

◆ unref()

void fawkes::RefCount::unref ( )

Decrement reference count and conditionally delete this instance.

This method will decrement the reference count of this message. If the reference count reaches zero the message will be deleted automatically. So it is not safe to use this instance after is has been unref()'ed. For the code calling

obj->unref();

should be considered equivalent to

delete obj;

. There is no guarantee whatsover that the object can still be used afterwards. It is however guaranteed, that the instance is not deleted/free from memory if there are still other applications using this instance that properly ref()'ed this instance before conditional delete was called.

Definition at line 99 of file refcount.cpp.

References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by SyncInterfaceListener::bb_interface_message_received(), fawkes::FawkesNetworkServerThread::broadcast(), fawkes::EclExternalBlackBoard::interfaces(), fawkes::RemoteBlackBoard::list(), fawkes::RemoteBlackBoard::list_all(), fawkes::BlackBoardNetworkHandler::loop(), fawkes::FawkesNetworkServerThread::loop(), NaoQiMotionThread::loop(), fawkes::ConfigNetworkHandler::loop(), ColliActThread::loop(), firevision::FuseClient::loop(), PointCloudDBROSCommThread::loop(), RosSkillerThread::loop(), fawkes::PluginNetworkHandler::loop(), fawkes::Interface::msgq_enqueue(), fawkes::Interface::msgq_enqueue_copy(), fawkes::ConnectionDispatcher::on_message_received(), firevision::FuseServerClientThread::process_getlutlist_message(), fawkes::BlackBoardInterfaceProxy::process_interface_message(), fawkes::FawkesNetworkClientRecvThread::recv(), fawkes::FawkesNetworkTransceiver::send(), firevision::FuseNetworkTransceiver::send(), fawkes::FawkesNetworkServerClientThread::set_clid(), fawkes::RemoteBlackBoard::try_aliveness_restore(), fawkes::FawkesNetworkClientRecvThread::~FawkesNetworkClientRecvThread(), fawkes::FawkesNetworkClientSendThread::~FawkesNetworkClientSendThread(), fawkes::FawkesNetworkServerClientSendThread::~FawkesNetworkServerClientSendThread(), firevision::FuseClient::~FuseClient(), and firevision::FuseServerClientThread::~FuseServerClientThread().


The documentation for this class was generated from the following files: