00001 /* 00002 wefts_critical.h 00003 Execution barrier for wefts. 00004 00005 $Id: wefts_critical.h,v 1.4 2004/04/05 12:42:06 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 00029 namespace Wefts 00030 { 00031 00128 class CriticalSection: public CleanupHandler 00129 { 00131 int m_signedIn; 00132 00134 int m_signRequests; 00135 00137 int m_enterRequests; 00138 00140 int m_fenceCount; 00141 00144 bool m_achieved; 00145 00147 Mutex m_mutex; 00148 00153 Condition m_signinCond; 00154 00159 Condition m_enterCond; 00160 00161 public: 00165 CriticalSection(); 00166 00212 bool enter( bool fence=true, bool timed=false, double time = 0 ); 00213 00227 bool enter( double time, bool fence=true) { return enter( fence, true, time ); } 00228 00242 bool tryEnter(); 00243 00249 void leave(); 00250 00273 void signIn(); 00274 00280 void signOut(); 00281 00295 void checkPoint(); 00296 00297 virtual void handleCleanup( int code, void *caller=0 ); 00298 }; 00299 00300 } 00301 #endif 00302 /* end of wefts_critical.h */