critsec.h

Go to the documentation of this file.
00001 /**
00002  * \file critsec.h <mi32/critsec.h>
00003  * \brief Definition for Windows Critical section objects
00004  *
00005  * \if NODOC
00006  * $Id: critsec.h_v 1.5 2005/05/16 16:19:38 scowan Exp $
00007  *
00008  * $Log: critsec.h_v $
00009  * Revision 1.5  2005/05/16 16:19:38  scowan
00010  * Move lock class into dll and export.
00011  *
00012  * Revision 1.4  2004/10/07 15:35:32  mju
00013  * Add copy ctor and op=.
00014  *
00015  * Revision 1.3  2003/09/15 13:49:56  fileserver!dwilliss
00016  * Doxygen
00017  *
00018  * Revision 1.2  2002/01/16 18:13:32  scowan
00019  * Do stupid thing for MAC.
00020  *
00021  * Revision 1.1  2001/12/06 17:46:22  scowan
00022  * Initial revision
00023  *
00024  * \endif
00025 **/
00026 
00027 #ifndef  INC_MI32_CRITSEC_H
00028 #define  INC_MI32_CRITSEC_H
00029 
00030 #ifndef GENERATING_DOXYGEN_OUTPUT
00031 #if defined(WIN32)
00032 #ifndef _WINBASE_
00033 extern "C" {
00034 struct _RTL_CRITICAL_SECTION;
00035 }
00036 #endif
00037 #endif
00038 #endif // GENERATING_DOXYGEN_OUTPUT
00039 
00040 #include <mi32/stddefns.h>
00041 
00042 #ifdef MISYSTEMDLL
00043    #define CLASSLIBEXPORT MI_DLLCLASSEXPORT
00044 #else
00045    #define CLASSLIBEXPORT MI_DLLCLASSIMPORT
00046 #endif
00047 
00048 //! Critical section class for WIN32, UNIX and MAC platforms.  Currently only implemented for WIN32.
00049 class CLASSLIBEXPORT CRITICALSECTION {
00050    public:
00051 
00052       #ifndef GENERATING_DOXYGEN_OUTPUT
00053       class LOCK;
00054       friend class LOCK;
00055       #endif
00056 
00057       //! Default constructor.
00058       CRITICALSECTION (
00059          unsigned long SpinCount = 0   //!< How many times to check and yield before allocating a system resource
00060          );
00061          
00062       //! Destructor.
00063       ~CRITICALSECTION (
00064          );
00065          
00066       //! Set spin count for the critical section
00067       unsigned long SetSpinCount (
00068          unsigned long SpinCount       //!< How many times to check and yield before allocating a system resource
00069          );
00070 
00071    private:
00072       #ifndef GENERATING_DOXYGEN_OUTPUT
00073       #if defined(WIN32)
00074          _RTL_CRITICAL_SECTION* m_cs;
00075       #else
00076          void* m_cs;
00077       #endif
00078       
00079       CRITICALSECTION (const CRITICALSECTION& rhs);
00080       CRITICALSECTION& operator= (const CRITICALSECTION& rhs);
00081 
00082       #endif // GENERATING_DOXYGEN_OUTPUT
00083    };
00084 
00085 
00086 //! Control of entering an instance of a CRITICALSECTION upon initialization and
00087 //! released when out of scope.  Inlined for speed reasons.
00088 class CLASSLIBEXPORT CRITICALSECTION::LOCK {
00089    public:
00090       //! Default constructor - used to implement TryEnter() paradigm.
00091       LOCK ();
00092             
00093       //! Constructor - Get critical section or wait until it is available
00094       explicit LOCK (
00095          CRITICALSECTION& sc,
00096          bool EnterSection = true         //!< Flag to allow setting of non-multithread mode
00097          );
00098 
00099       //! Destructor - Releases critical section            
00100       ~LOCK ();
00101             
00102       //! Check if it is possible to enter a critical section
00103       //! @return 'True' if entered critical section, 'false' if not
00104       bool TryEnter (
00105          CRITICALSECTION& sc
00106          );
00107          
00108    private:
00109       #ifndef GENERATING_DOXYGEN_OUTPUT
00110       CRITICALSECTION* m_sc;  
00111       #endif // GENERATING_DOXYGEN_OUTPUT
00112    };
00113 
00114 #undef   CLASSLIBEXPORT
00115 #endif   //!< INC_MI32_CRITSEC_H

Generated on Wed May 31 15:26:49 2006 for TNTsdk by  doxygen 1.3.8-20040913