Fawkes API  Fawkes Development Version
fawkes::RefCount Class Reference

#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 37 of file refcount.h.

Constructor & Destructor Documentation

◆ RefCount()

fawkes::RefCount::RefCount ( )

Constructor.

Definition at line 55 of file refcount.cpp.

◆ ~RefCount()

fawkes::RefCount::~RefCount ( )
virtual

Destructor.

Definition at line 62 of file refcount.cpp.

References fawkes::Mutex::lock().

Member Function Documentation

◆ ref()

void fawkes::RefCount::ref ( )

Increment reference count.

Exceptions
DestructionInProgressExceptionThrown if the only other reference holder for this instance was just deleting the instance when you tried to reference it.
See also
recount();

Definition at line 73 of file refcount.cpp.

Referenced by SyncInterfaceListener::bb_interface_message_received(), ColliActThread::loop(), RosSkillerThread::loop(), and fawkes::NetworkConfiguration::NetConfValueIterator::NetConfValueIterator().

◆ 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 126 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 101 of file refcount.cpp.

Referenced by SyncInterfaceListener::bb_interface_message_received(), fawkes::NetworkConfiguration::get_bool(), fawkes::NetworkConfiguration::get_comment(), fawkes::NetworkConfiguration::get_default_comment(), fawkes::NetworkConfiguration::get_float(), fawkes::NetworkConfiguration::get_int(), fawkes::NetworkConfiguration::get_string(), fawkes::NetworkConfiguration::get_uint(), fawkes::NetworkConfiguration::get_value(), ColliActThread::loop(), RosSkillerThread::loop(), firevision::FuseClient::loop(), fawkes::Interface::msgq_enqueue(), firevision::FuseNetworkTransceiver::send(), fawkes::FawkesNetworkServerClientThread::set_clid(), firevision::FuseClient::~FuseClient(), firevision::FuseServerClientThread::~FuseServerClientThread(), fawkes::NetworkConfiguration::NetConfValueIterator::~NetConfValueIterator(), and fawkes::NetworkConfiguration::~NetworkConfiguration().


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