00001 /* 00002 wefts_critical.h 00003 Execution barrier for wefts. 00004 00005 $Id: wefts_critical.h,v 1.1 2004/03/10 19:53:30 jonnymind Exp $ 00006 --------------------------------------------- 00007 Begin : Wed, 10 Mar 2004 16:31:37 +0100 00008 Author : Giancarlo Niccolai 00009 00010 Last modified because: 00011 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 00022 #ifndef WT_CRITICAL_SECTION_H 00023 #define WT_CRITICAL_SECTION_H 00024 00025 #include <wefts_mutex.h> 00026 #include <wefts_cond.h> 00027 #include <wefts_cleanup.h> 00028 00122 namespace Wefts 00123 { 00124 00125 class CriticalSection: public CleanupHandler 00126 { 00128 int m_signedIn; 00129 00131 int m_signRequests; 00132 00134 int m_enterRequests; 00135 00137 int m_fenceCount; 00138 00141 bool m_achieved; 00142 00144 Mutex m_mutex; 00145 00150 Condition m_signinCond; 00151 00156 Condition m_enterCond; 00157 00158 public: 00162 CriticalSection(); 00163 00209 bool enter( bool fence=true, bool timed=false, double time = 0 ); 00210 00224 bool enter( double time, bool fence=true) { return enter( fence, true, time ); } 00225 00239 bool tryEnter(); 00240 00246 void leave(); 00247 00270 void signIn(); 00271 00277 void signOut(); 00278 00292 void checkPoint(); 00293 00294 virtual void handleCleanup( int code, void *caller=0 ); 00295 }; 00296 00297 } 00298 #endif 00299 /* end of wefts_critical.h */