MboSynch.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Copyright (c) 2001 - 2008 Marcus Boerger.  All rights reserved.
00003 *
00004 * This library is free software; you can redistribute it and/or
00005 * modify it under the terms of the GNU Lesser General Public
00006 * License as published by the Free Software Foundation; either
00007 * version 2.1 of the License, or (at your option) any later version.
00008 *
00009 * This library is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 * Lesser General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU Lesser General Public
00015 * License along with this library; if not, write to the Free Software
00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017 * ========================================================================= */
00018 
00019 /* ------------------------------------------------------------------------ */
00020 /* Name:      MboSynch.h / MboSynch.cpp
00021  *
00022  * Requires:  
00023  * - Mbo.h
00024  */
00217 /* ------------------------------------------------------------------------ */
00218 
00219 #ifndef _MBOSYNCH_H_
00220 #define _MBOSYNCH_H_
00221 
00222 #include "Mbo.h"
00223 #include "MboDebugTrace.h"
00224 #include <assert.h>
00225 #include <vector>
00226 
00227 #if defined(_MSC_VER)
00228 # pragma warning(push)
00229 # pragma warning(disable: 4251) // disable warning C4251: '...' : class '...' needs to have dll-interface to be used by clients of class '...'
00230 # pragma warning(disable: 4275) // non dll-interface class '...' used as base for dll-interface class '...'
00231 # pragma warning(disable: 4290) // C++-exception-specification ignored
00232 # ifndef _CPPRTTI
00233 #  error You must compile using RTTI
00234 # endif // _CPPRTTI
00235 #endif // _MSC_VER
00236 
00237 namespace mbo
00238 {
00239 
00240 // define the time to wait between to Try/Leave cyles in MultiLock::Enter()
00241 #ifndef MBO_MULTI_LOCK_SLEEPTIME
00242 # define MBO_MULTI_LOCK_SLEEPTIME 5
00243 #endif
00244 
00245 #if !defined(LONG) && _MSC_VER >= 1300
00246 //# error Wrong includes or macro definitions that control includes
00247 #endif
00248 
00249 typedef LONG IncDecVal;  
00251 class CLock; // Forward declaration
00252 
00253 /* ------------------------------------------------------------------------ */
00258 class MBO_API ILock // lx
00259 {
00260 public:
00263     virtual ~ILock() {}
00264 
00267     virtual void Enter() const =0;
00268     
00271     virtual void Leave() const =0;
00272 
00281     virtual unsigned long GetLevel() const =0;
00282 };
00283 
00284 /* ------------------------------------------------------------------------ */
00289 class MBO_API IEvent // evt
00290 {
00291 public:
00294     virtual ~IEvent() {}
00295 
00298     virtual void Set() =0;
00299 
00300 
00303     virtual void Reset() =0;
00304 
00313     virtual void Pulse() =0;
00314 
00326     virtual bool Wait(_IN size_t nTime = INFINITE) const =0;
00327 };
00328 
00329 /* ------------------------------------------------------------------------ */
00334 class MBO_API ICriticalSection // mx
00335 {
00336 public:
00337 
00340     virtual ~ICriticalSection() {}
00341 
00344     virtual void Enter() const =0;
00345 
00348     virtual void Leave() const =0;
00349 
00352     virtual CLock GetLock() const =0;
00353 
00359     virtual unsigned long GetLevel() const =0;
00360 };
00361 
00362 /* ------------------------------------------------------------------------ */
00377 class MBO_API IMutex: public ICriticalSection // mx
00378 {
00379 friend class MutexList;  
00380 public:
00383     virtual void Enter() const { while (!Try(INFINITE)); }
00384     
00391     virtual bool Try(_IN DWORD nMilliseconds = 0) const =0;
00392 
00402     virtual CLock GetLock() const =0;
00403 
00404 protected:
00405 
00408     virtual HANDLE GetHandle() const { return INVALID_HANDLE_VALUE; }
00409 
00412     virtual IncDecVal IncEntered() const =0;
00413 
00416     virtual IncDecVal DecEntered() const =0;
00417 };
00418 
00419 /* ------------------------------------------------------------------------ */
00424 class MBO_API CLockFake: public ILock // lx
00425 {
00426 public:
00427 
00428     inline  CLockFake() {} 
00429     inline  explicit CLockFake(_IN const ICriticalSection*) {} 
00430     inline  explicit CLockFake(_IN const ILock&) {} 
00432     inline virtual void Enter() const {} 
00433     inline virtual void Leave() const {} 
00434     inline virtual unsigned long GetLevel() const { return 1; }; 
00435 };
00436 
00437 /* ------------------------------------------------------------------------ */
00445 class MBO_API CLockSingle: public ILock // lx
00446 {
00447 friend CLock;
00448 public:
00456 
00469 
00479 
00486 
00493 
00499 
00507 
00511 
00517 
00544 
00562 
00583 
00597 
00610 
00630 
00654 
00662 
00672 
00680 
00692 
00702 
00714 
00720 
00731 
00737 
00741 
00745 
00747 
00748 
00749 
00750 
00751 
00755 
00758 
00762 
00764 
00765 
00766 
00773 
00784 
00786 
00787 
00791 
00796 
00806 
00819 
00823 
00834 
00840 
00842 
00843 
00849 
00853 
00857 
00862 
00871 
00877 
00884 
00891 
00898 
00906 
00916 
00925 
00930 
00936 
00943 
00951 
00963 
00978 
00984 
00988 
00992 
00996 
01004 
01007 
01012 
01019 
01025 
01029 
01033 
01036 
01041 
01050 
01056 
01060 
01064 
01072 
01075 
01082 
01088 
01092 
01095 
01105 
01113 
01117 
01121 
01125 
01133 
01136 
01143 
01152 
01158 
01162 
01167 
01177 
01186 
01188 
01189 
01190 
01191 
01192 
01198 
01200 
01204 
01208 
01210 
01217 
01221 
01225 
01229 
01233 
01236 
01242 
01265 
01272 
01289 
01296 
01309 
01321 
01323 
01335 
01342 
01346 
01347 
01348 
01349 
01350 
01351 
01358 
01365 
01372 
01380 
01387 
01391 
01392 
01393 
01394 
01395 
01396 
01403 
01410 
01417 
01431 
01448 
01451 
01452 
01453 
01454 
01455 
01456 
01457 
01459 
01460 
01465 
01469 
01578 

  Hosted on code.google.com  
© Marcus Börger
Generated on Fri Jan 18 21:21:08 2008 for MBO-lib by doxygen 1.5.4