00001 /// \file CATMutex.h 00002 /// \brief Defines the interface to mutexes for thread synchronization. 00003 /// \ingroup CAT 00004 /// 00005 /// Copyright (c) 2003-2008 by Michael Ellison. 00006 /// See COPYING.txt for the \ref gaslicense License (MIT License). 00007 /// 00008 // $Author: mikeellison $ 00009 // $Date: 2008-01-21 08:33:12 -0600 (Mon, 21 Jan 2008) $ 00010 // $Revision: $ 00011 // $NoKeywords: $ 00012 00013 #ifndef _CATMutex_H_ 00014 #define _CATMutex_H_ 00015 00016 #include "CATInternal.h" 00017 00018 /// \class CATMutex 00019 /// \brief Defines the interface to mutexes for thread synchronization. 00020 /// \ingroup CAT 00021 /// 00022 /// CATMutex provides a per-thread synchronization object. While one thread 00023 /// owns a mutex, another may not receive it and will have to wait until 00024 /// it is released. A single thread, however, will not be forced to wait 00025 /// if it tries to acquire the mutex twice before releasing it - just make 00026 /// sure to call Release() for each Wait(). 00027 class CATMutex 00028 { 00029 public: 00030 CATMutex(); 00031 virtual ~CATMutex(); 00032 00033 /// Wait() waits up to [milliseconds] milliseconds to obtain the 00034 /// mutex. 00035 /// 00036 /// Check the result code here! It can very easily time out. 00037 /// 00038 /// The default, however, is an infinite wait. 00039 /// 00040 /// You must call Release() when done. 00041 /// 00042 /// Remember that CATMutex only blocks per-thread. A single thread 00043 /// will not deadlock if it waits on the mutex twice in a row. However, 00044 /// it should also release it twice in a row if it does so. 00045 /// 00046 /// \param milliseconds - milliseconds to wait while trying to get synch 00047 /// 00048 /// \sa Release() 00049 CATResult Wait(CATUInt32 milliseconds = 0xFFFFFFFF); 00050 00051 /// Release() releases an acquired mutex. 00052 /// 00053 /// \sa Wait() 00054 CATResult Release(); 00055 00056 private: 00057 CATMutex& operator=(const CATMutex& srcMutex) 00058 { 00059 CATASSERT(false,"Copying mutexes is not supported."); 00060 return *this; 00061 } 00062 00063 // Platform specific mutex handles 00064 HANDLE fMutexHandle; 00065 }; 00066 00067 00068 #endif // _CATMutex_H_ 00069 00070