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

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

# Mers::Executives::DeductiveController::Rtapi::ThreadSafeObjectQueue Class Reference

`#include <ThreadSafeObjectQueue.h>`

Inheritance diagram for Mers::Executives::DeductiveController::Rtapi::ThreadSafeObjectQueue:

[legend]
Collaboration diagram for Mers::Executives::DeductiveController::Rtapi::ThreadSafeObjectQueue:

[legend]
List of all members.

## Public Member Functions
| ThreadSafeObjectQueue (int myMaxQueueSize=-1)
virtual | ~ThreadSafeObjectQueue ()
virtual int | enqueue (Mers::Utils::Lang::BaseModelObject *element)
virtual int | dequeue (Mers::Utils::Lang::BaseModelObject *&element, bool wait=true)
virtual int | peekQueue (Mers::Utils::Lang::BaseModelObject *&element)
virtual unsigned int | getLength ()
virtual bool | isEmpty ()
virtual void | waitForEmpty ()
virtual void | printArray (std::ostream &out, char const *seperator)
## Protected Member Functions
void | lock ()
void | unlock ()
## Protected Attributes
pthread_mutex_t | queueMutex
| mutex that allows multiple threads to access the queue
pthread_cond_t | queueNotEmpty
| this condition is asserted whenever something is inserted into queue
pthread_cond_t | queueIsEmpty

## Detailed Description

A Thread Safe Dynamically sized Queue of BaseModelObjects implimented using ObjectArray.

Author:
  Paul H. Elliott

Definition at line 48 of file ThreadSafeObjectQueue.h.

## Constructor & Destructor Documentation

ThreadSafeObjectQueue::ThreadSafeObjectQueue | ( | int | myMaxQueueSize = `-1` | ) |

Creates a new, empty thread-safe queue of BaseModelObject with the specified maximum size

Parameters:

  | myMaxQueueSize | a positive value limits the queue to having at most myMaxQueueSize elements. The queue will be resized to hold myMaxQueueSize elements. If a negative value is specified, the queue will grow to fit the number of inserted elements as space permits.

Definition at line 30 of file ThreadSafeObjectQueue.cpp.

References queueIsEmpty, queueMutex, and queueNotEmpty.

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

Destroys the queue

Definition at line 53 of file ThreadSafeObjectQueue.cpp.

References queueIsEmpty, queueMutex, and queueNotEmpty.

## Member Function Documentation

int ThreadSafeObjectQueue::enqueue | ( | Mers::Utils::Lang::BaseModelObject * | element | ) | `[virtual]`

adds the specified element to the end of the queue, adding space as necessary

Parameters:

  | element | the element being added to the queue

Returns:
  0 on success or a positive number if the queue could not be resized

Definition at line 103 of file ThreadSafeObjectQueue.cpp.

References lock(), queueNotEmpty, and unlock().

Referenced by Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::queue_command(), Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::queue_find_mode_estimate(), Mers::Executives::DeductiveController::Rtapi::MR::MR_rtapi::queue_goal(), Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::queue_initial_state(), Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::queue_observation(), Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::queue_observations_and_time(), Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::queue_report_full_state(), Mers::Executives::DeductiveController::Rtapi::MR::MR_rtapi::queue_request_MR(), Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::queue_start_command_and_time(), Mers::Executives::DeductiveController::Rtapi::MR::MR_rtapi::queue_state_update(), Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::~ME_rtapi(), and Mers::Executives::DeductiveController::Rtapi::MR::MR_rtapi::~MR_rtapi().

Here is the call graph for this function:

int ThreadSafeObjectQueue::dequeue | ( | Mers::Utils::Lang::BaseModelObject *& | element,
|  | bool | wait = `true` |
| ) |  |  | `[virtual]`

returns the element at the beginning of the queue and removes it from the queue

Parameters:

  | element | the first element is returned here
  | wait | if true, this procedure will only return when it has successfully dequeued an element or if an error occured. if false, this procedure will attempt to dequeue an element and return an error if there was an error

Returns:
  0 on success, a positive number if the queue was empty. This also sets element to NULL

Definition at line 132 of file ThreadSafeObjectQueue.cpp.

References isEmpty(), lock(), queueIsEmpty, queueMutex, queueNotEmpty, and unlock().

Referenced by Mers::Executives::DeductiveController::Rtapi::MR::MR_dispatcher::run(), and Mers::Executives::DeductiveController::Rtapi::ME::ME_dispatcher::run().

Here is the call graph for this function:

int ThreadSafeObjectQueue::peekQueue | ( | Mers::Utils::Lang::BaseModelObject *& | element | ) | `[virtual]`

returns the element at the beginning of the queue but does not remove it from the queue

Parameters:

  | element | the first element is returned here

Returns:
  0 on success, a positive number if the queue was empty. This also sets element to NULL

Definition at line 172 of file ThreadSafeObjectQueue.cpp.

References lock(), and unlock().

Here is the call graph for this function:

unsigned int ThreadSafeObjectQueue::getLength | ( |  | ) | `[virtual]`

returns the current length of the queue (number of elements in it).

Returns:
  the number of elements in the queue

Definition at line 185 of file ThreadSafeObjectQueue.cpp.

References lock(), and unlock().

Here is the call graph for this function:

bool ThreadSafeObjectQueue::isEmpty | ( |  | ) | `[virtual]`

returns true if a call to getLength() would return 0

Returns:
  true if the array length is currently 0

Definition at line 197 of file ThreadSafeObjectQueue.cpp.

References lock(), and unlock().

Referenced by dequeue().

Here is the call graph for this function:

void ThreadSafeObjectQueue::waitForEmpty | ( |  | ) | `[virtual]`

returns when the queue is empty

Definition at line 209 of file ThreadSafeObjectQueue.cpp.

References lock(), queueIsEmpty, queueMutex, and unlock().

Referenced by Mers::Executives::DeductiveController::Rtapi::ME::ME_rtapi::~ME_rtapi(), and Mers::Executives::DeductiveController::Rtapi::MR::MR_rtapi::~MR_rtapi().

Here is the call graph for this function:

void ThreadSafeObjectQueue::printArray | ( | std::ostream & | out,
|  | char const * | seperator |
| ) |  |  | `[virtual]`

Prints out the Dynamic Queue as a sequence of elements. It sperates each element with seperator. each element is printed by calling printElement()

Parameters:

  | out | the ostream being written to
  | seperator | the seperator used between each element

Definition at line 225 of file ThreadSafeObjectQueue.cpp.

References lock(), and unlock().

Here is the call graph for this function:

void Mers::Executives::DeductiveController::Rtapi::ThreadSafeObjectQueue::lock | ( |  | ) | `[inline, protected]`

locks this queue for exclusive access to the queue's functions

Definition at line 143 of file ThreadSafeObjectQueue.h.

References queueMutex.

Referenced by dequeue(), enqueue(), getLength(), isEmpty(), peekQueue(), printArray(), and waitForEmpty().

void Mers::Executives::DeductiveController::Rtapi::ThreadSafeObjectQueue::unlock | ( |  | ) | `[inline, protected]`

unlocks this queue so that another process can access the queue

Definition at line 150 of file ThreadSafeObjectQueue.h.

References queueMutex.

Referenced by dequeue(), enqueue(), getLength(), isEmpty(), peekQueue(), printArray(), and waitForEmpty().

## Member Data Documentation

pthread_cond_t Mers::Executives::DeductiveController::Rtapi::ThreadSafeObjectQueue::queueIsEmpty`[protected]`

this condition is asserted whenever the last element of the queue is dequeued

Definition at line 167 of file ThreadSafeObjectQueue.h.

Referenced by dequeue(), ThreadSafeObjectQueue(), waitForEmpty(), and ~ThreadSafeObjectQueue().

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

- /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Rtapi/ThreadSafeObjectQueue.h
- /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Rtapi/ThreadSafeObjectQueue.cpp