00001 /* 00002 * $Id: ConditionVar.h 562 2007-12-02 08:04:16Z mindstorm2600 $ 00003 * 00004 * X-VR2 00005 * 00006 * Copyright (C) Juan V. Guerrero 2007 00007 * 00008 * Juan V. Guerrero <mindstorm2600@users.sourceforge.net> 00009 * 00010 * This program is free software, distributed under the terms of 00011 * the GNU General Public License Version 2. See the LICENSE file 00012 * at the top of the source tree. 00013 */ 00014 #ifndef __SHARED_VAR_h__ 00015 #define __SHARED_VAR_h__ 00016 00017 #include<xvr2/CoreExceptions.h> 00018 #include<xvr2/Threading.h> 00019 #include<xvr2/Mutex.h> 00020 #ifdef USE_POSIX_THREADS 00021 #include<pthread.h> 00022 #endif 00023 00024 namespace xvr2{ 00034 class ConditionVar:public Threading{ 00035 private: 00036 protected: 00037 #ifdef USE_POSIX_THREADS 00038 pthread_cond_t __cvar; 00039 #endif 00040 void init(); 00041 void destroy(); 00042 public: 00043 ConditionVar(); 00044 ~ConditionVar(); 00048 void signal(); 00052 void broadcast(); 00056 void wait(Mutex *mutex); 00060 void timedWait(Mutex *mutex, long seconds = 1, long nanoseconds = 0); 00062 static void wait(ConditionVar *cv, Mutex *mutex); 00064 static void timedWait(ConditionVar *cv, Mutex *mutex, long seconds = 1, long nanoseconds = 0); 00065 }; 00066 } 00067 00068 #endif