#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/OS/Threads/Posix/ConditionalMutex.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVLTHREADS_CONDITIONAL_HEADER #define RAVLTHREADS_CONDITIONAL_HEADER 1 ///////////////////////////////////////////////// //! rcsid="$Id: ConditionalMutex.hh,v 1.2 2001/05/10 13:44:46 craftit Exp $" //! file="Ravl/OS/Threads/Posix/ConditionalMutex.hh" //! lib=RavlThreads //! userlevel=Normal //! docentry="Ravl.OS.Threads" //! author="Charles Galambos" //! date="02/07/99" #include "Ravl/config.h" #if !defined(_POSIX_SOURCE) && !defined(__sgi__) #define _POSIX_SOURCE 1 #endif #if defined(__sol2__) #include #endif #include #include "Ravl/Types.hh" #include "Ravl/Threads/Mutex.hh" namespace RavlN { //! userlevel=Normal //: Conditional variable. // See SemaphoreC for an example of its use. class ConditionalMutexC : public MutexC { public: ConditionalMutexC() #if RAVL_HAVE_PTHREAD_COND { if(pthread_cond_init(&cond,0)) Error("pthread_cond_init failed. \n"); } #else ; #endif //: Constructor. ~ConditionalMutexC(); //: Destructor void Broadcast() #if RAVL_HAVE_PTHREAD_COND { pthread_cond_broadcast(&cond); } #else ; #endif //: Boardcast a signal to all waiting threads. // Always succeeds. void Signal() #if RAVL_HAVE_PTHREAD_COND { pthread_cond_signal(&cond); } #else ; #endif //: Signal one waiting thread. // Always succeeds. void Wait() #if RAVL_HAVE_PTHREAD_COND { pthread_cond_wait(&cond,&mutex); } #else ; #endif //: Wait for conditional. // This unlocks the mutex and then waits for a signal. // from either Signal or Broadcast, when it get it // the mutex is re-locked and control returned to the // program.

// Always succeeds. bool Wait(RealT maxTime); //: Wait for conditional. // This unlocks the mutex and then waits for a signal. // from either Signal, Broadcast or timeout, when it get it // the mutex is re-locked and control returned to the // program.

// Returns false, if timeout occures. private: #if RAVL_HAVE_PTHREAD_COND pthread_cond_t cond; #endif }; } #endif