00001 /* 00002 wefts_cond.h 00003 Abstract class implementing a condition variable. 00004 00005 $Id: wefts_cond.h,v 1.7 2003/08/16 13:23:58 jonnymind Exp $ 00006 ---------------------------------------------- 00007 Begin : 2003-08-02 00:10 00008 Author : Giancarlo Niccolai 00009 00010 Last modified because: 00011 Implementing OS independent base threading 00012 */ 00013 00014 /************************************************************************** 00015 * This program is free software; you can redistribute it and/or modify * 00016 * it under the terms of the GNU Library General Public License as * 00017 * published by the Free Software Foundation; either version 2.1 of the * 00018 * License, or (at your option) any later version. * 00019 ***************************************************************************/ 00020 00021 #ifndef WT_COND_H 00022 #define WT_COND_H 00023 00024 #include <wefts_mutex.h> 00025 #include <wefts_cleanup.h> 00026 00027 namespace Wefts { 00028 00044 class Condition 00045 { 00046 protected: 00048 OSCondition m_cond; 00053 Mutex *m_my_mutex; 00054 CleanupItem m_whenStopped; 00055 00056 00057 public: 00060 Condition( Mutex *mtx=0 ) { m_my_mutex = mtx; m_whenStopped.first = 0;} 00061 ~Condition() {} 00062 00072 virtual inline bool wait() { 00073 return m_cond.wait( m_my_mutex->m_mutex, m_whenStopped ); 00074 } 00075 00076 void setMutex( Mutex *mtx) { m_my_mutex = mtx; } 00077 00096 virtual inline bool wait( long seconds, long nanoseconds) 00097 { 00098 return m_cond.timedWait( m_my_mutex->m_mutex, seconds, nanoseconds, m_whenStopped ); 00099 } 00100 00101 00113 inline int wait( double seconds ) 00114 { 00115 return wait( long( seconds ), 00116 long( (seconds - long(seconds)) *1000000000l) ); 00117 } 00118 00122 virtual inline void signal() { m_cond.signal(); } 00123 00133 inline void onStop( CleanupHandler *guard=0, int param=0) { 00134 m_whenStopped.first = guard; 00135 m_whenStopped.second = param; 00136 } 00137 }; 00138 00139 } 00140 00141 #endif 00142 /* end of wefts_cond.h */