- Main Page
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Mers::Utils::Lang::ReferencedObject Class Reference

`#include <ReferencedObject.h>`

Inheritance diagram for Mers::Utils::Lang::ReferencedObject:

[legend]
List of all members.

## Public Member Functions
| ReferencedObject ()
virtual | ~ReferencedObject ()
virtual void | addReference ()
virtual void | removeReference ()
## Protected Member Functions
virtual void | lockReferencedObject ()
virtual void | unlockReferencedObject ()
## Protected Attributes
unsigned int | mNumberOfReferences
| The current number of references to this object.
pthread_mutex_t | mReferencedObjectMutex

## Detailed Description

Generic class that automatically handles reference counting and object deletion upon the removal of all the objects references.

Note that in a multi-threaded environment, having a referenced object shared between threads allows each thread to de-reference the shared data structures, so they will only be destroyed after each thread has completed. This eliminates the need to lock threads during cleanup such that a single thread must be responsible for ensuring the other threads have finished and that its now safe to cleanup the data structures.

This object performs its own locking when adding and removing references so as to ensure thread-safety.

Author:
  Paul H. Elliott

Definition at line 42 of file ReferencedObject.h.

## Constructor & Destructor Documentation

ReferencedObject::ReferencedObject | ( |  | ) |

Creates the ReferencedObject with a default reference count of 0.

Definition at line 20 of file ReferencedObject.cpp.

References mReferencedObjectMutex.

ReferencedObject::~ReferencedObject | ( |  | ) | `[virtual]`

Destroys this object.

Definition at line 31 of file ReferencedObject.cpp.

References mReferencedObjectMutex.

## Member Function Documentation

void ReferencedObject::addReference | ( |  | ) | `[virtual]`

Adds a reference to this object. This object will only be destroyed when all the references go to zero.

Definition at line 39 of file ReferencedObject.cpp.

References lockReferencedObject(), mNumberOfReferences, and unlockReferencedObject().

Referenced by Mers::Executives::DeductiveController::Observation::DiscreteValue::DiscreteValue(), Mers::Interfaces::ElapsedTimeService::ElapsedTimeService(), Mers::Executives::DeductiveController::Rtapi::ME::ME_dispatcher::ME_dispatcher(), Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::ME_rtapi(), Mers::Executives::DeductiveController::Rtapi::MR::MR_dispatcher::MR_dispatcher(), Mers::Executives::DeductiveController::Rtapi::MR::MR_rtapi::MR_rtapi(), Mers::Interfaces::ExecutionInterfaceBase::setTaskFactory(), Mers::Executives::DeductiveController::Observation::DiscreteVariable::setValues(), and Mers::Interfaces::TimedExecutionInterface::TimedExecutionInterface().

Here is the call graph for this function:

void ReferencedObject::removeReference | ( |  | ) | `[virtual]`

Removes a reference to this object. This object will only be destroyed when all the references go to zero.

Definition at line 49 of file ReferencedObject.cpp.

References lockReferencedObject(), mNumberOfReferences, and unlockReferencedObject().

Referenced by Mers::Interfaces::TimedExecutionInterface::setTaskFactory(), Mers::Interfaces::ExecutionInterfaceBase::setTaskFactory(), Mers::Executives::DeductiveController::Observation::DiscreteVariable::setValues(), Mers::Executives::DeductiveController::Observation::DiscreteValue::~DiscreteValue(), Mers::Executives::DeductiveController::Observation::DiscreteVariable::~DiscreteVariable(), Mers::Interfaces::ElapsedTimeService::~ElapsedTimeService(), Mers::Interfaces::ExecutionInterfaceBase::~ExecutionInterfaceBase(), Mers::Executives::DeductiveController::Rtapi::ME::ME_dispatcher::~ME_dispatcher(), Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::~ME_rtapi(), Mers::Executives::DeductiveController::Rtapi::MR::MR_dispatcher::~MR_dispatcher(), Mers::Executives::DeductiveController::Rtapi::MR::MR_rtapi::~MR_rtapi(), and Mers::Interfaces::TimedExecutionInterface::~TimedExecutionInterface().

Here is the call graph for this function:

void ReferencedObject::lockReferencedObject | ( |  | ) | `[protected, virtual]`

Places a lock on this referenced object which causes serial access to the addReference and removeReference functions. Only one may be active at the same time.

Definition at line 70 of file ReferencedObject.cpp.

References mReferencedObjectMutex.

Referenced by addReference(), and removeReference().

void ReferencedObject::unlockReferencedObject | ( |  | ) | `[protected, virtual]`

Removes the lock placed on the addReference/removeReference functions so that other threads are now able to adjust the reference count.

Definition at line 77 of file ReferencedObject.cpp.

References mReferencedObjectMutex.

Referenced by addReference(), and removeReference().

## Member Data Documentation

pthread_mutex_t Mers::Utils::Lang::ReferencedObject::mReferencedObjectMutex`[protected]`

A Mutex that is used to lock and unlock access to the functions that modify the reference count.

Definition at line 88 of file ReferencedObject.h.

Referenced by lockReferencedObject(), ReferencedObject(), unlockReferencedObject(), and ~ReferencedObject().

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

- /Users/fpy/titan-1-5-MBARI/Mers/Utils/Lang/ReferencedObject.h
- /Users/fpy/titan-1-5-MBARI/Mers/Utils/Lang/ReferencedObject.cpp