Fawkes API
Fawkes Development Version
|
Reference counting base class. More...
#include <core/utils/refcount.h>
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... | |
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.
Definition at line 32 of file refcount.h.
fawkes::RefCount::RefCount | ( | ) |
Constructor.
Definition at line 50 of file refcount.cpp.
|
virtual |
Destructor.
Definition at line 58 of file refcount.cpp.
void fawkes::RefCount::ref | ( | ) |
Increment reference count.
DestructionInProgressException | Thrown if the only other reference holder for this instance was just deleting the instance when you tried to reference it. |
Definition at line 70 of file refcount.cpp.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
Referenced by SyncInterfaceListener::bb_interface_message_received(), fawkes::FawkesNetworkServerThread::broadcast(), fawkes::FawkesNetworkServerThread::dispatch(), fawkes::BlackBoardNetworkHandler::handle_network_message(), fawkes::ConfigNetworkHandler::handle_network_message(), fawkes::PluginNetworkHandler::handle_network_message(), fawkes::RemoteBlackBoard::inbound_received(), fawkes::EclExternalBlackBoard::interfaces(), NaoQiMotionThread::loop(), ColliActThread::loop(), PointCloudDBROSCommThread::loop(), RosSkillerThread::loop(), fawkes::Interface::msgq_append(), and fawkes::NetworkConfiguration::NetConfValueIterator::NetConfValueIterator().
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!
Definition at line 125 of file refcount.cpp.
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
should be considered equivalent to
. 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().