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

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

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #if !defined(AFX_THREADSAFEOBJECTQUEUE_H__F21143C5_DC28_426E_AD7E_4B1D10A8E476__INCLUDED_)
    00015 #define AFX_THREADSAFEOBJECTQUEUE_H__F21143C5_DC28_426E_AD7E_4B1D10A8E476__INCLUDED_
    00016
    00017 #include <Mers/Utils/Containers/ObjectQueue.h>
    00018 #include <Mers/Utils/Lang/ReferencedObject.h>
    00019
    00020 #if _MSC_VER > 1000
    00021 #pragma once
    00022 #endif // _MSC_VER > 1000
    00023
    00024 // this should probably be installed on the build system, as with flex...
    00025 #ifdef _MSC_VER
    00026 #include "pthread.h"
    00027 #else
    00028
    00029 #ifdef TARGET_DSPBIOS
    00030 #include "pthread_dspbios.h"
    00031 #else
    00032 #include <pthread.h>
    00033 #endif
    00034
    00035 #endif
    00036
    00037 namespace Mers {
    00038         namespace Executives {
    00039                 namespace DeductiveController {
    00040                         namespace Rtapi {
    00041
    00048                                 class ThreadSafeObjectQueue : public Mers::Utils::Containers::ObjectQueue,
    00049                                         public Mers::Utils::Lang::ReferencedObject
    00050                                 {
    00051                                 public:
    00053                                         // Constructors
    00055
    00065                                         ThreadSafeObjectQueue(int myMaxQueueSize = -1);
    00066
    00068                                         // Destructors
    00070
    00074                                         virtual ~ThreadSafeObjectQueue();
    00075
    00077                                         // Functions
    00079
    00087                                         virtual int enqueue(Mers::Utils::Lang::BaseModelObject * element);
    00099                                         virtual int dequeue(Mers::Utils::Lang::BaseModelObject * &element, bool wait = true);
    00107                                         virtual int peekQueue(Mers::Utils::Lang::BaseModelObject * &element);
    00108
    00113                                         virtual unsigned int getLength();
    00118                                         virtual bool isEmpty();
    00119
    00123                                         virtual void waitForEmpty();
    00124
    00125 #ifndef EMBEDDED
    00126
    00133                                         virtual void printArray(std::ostream &out, char const * seperator);
    00134 #endif
    00135                                 protected:
    00137                                         // Functions
    00139
    00143                                         void lock()
    00144                                         {
    00145                                                 pthread_mutex_lock(&queueMutex);
    00146                                         }
    00150                                         void unlock()
    00151                                         {
    00152                                                 pthread_mutex_unlock(&queueMutex);
    00153                                         }
    00154
    00155                                 protected:
    00157                                         // Data
    00159
    00161                                         pthread_mutex_t queueMutex;
    00162
    00164                                         pthread_cond_t queueNotEmpty;
    00167                                         pthread_cond_t queueIsEmpty;
    00168                                 };
    00169                         }
    00170                 }
    00171         }
    00172 }
    00173
    00174 #endif // !defined(AFX_THREADSAFEOBJECTQUEUE_H__F21143C5_DC28_426E_AD7E_4B1D10A8E476__INCLUDED_)