_mutex_win32.h

Go to the documentation of this file.
00001 
00025 /* === S T A R T =========================================================== */
00026 
00027 #ifndef __ETL__MUTEX_WIN32_H_
00028 #define __ETL__MUTEX_WIN32_H_
00029 
00030 /* === H E A D E R S ======================================================= */
00031 
00032 #include <windows.h>
00033 // extern HANDLE CreateMutex(NULL, FALSE, NULL);
00034 // extern CloseHandle(handle);
00035 // extern WaitForSingleObject(handle, INFINITE);
00036 // extern ReleaseMutex(handle);
00037 
00038 /* === M A C R O S ========================================================= */
00039 
00040 
00041 /* === C L A S S E S & S T R U C T S ======================================= */
00042 
00043 _ETL_BEGIN_NAMESPACE
00044 
00045 class mutex
00046 {
00047     HANDLE handle;
00048 public:
00049 
00050     mutex()
00051     { handle = CreateMutex(NULL, FALSE, NULL); }
00052 
00053     ~mutex()
00054     { CloseHandle(handle); }
00055 
00057     class lock
00058     {
00059         mutex *_mtx;
00060     public:
00061         lock(mutex &x):_mtx(&x) { _mtx->lock_mutex(); }
00062         ~lock() { _mtx->unlock_mutex(); }
00063         mutex &get() { return *_mtx; }
00064     };
00065 
00066     void lock_mutex(void)
00067     { WaitForSingleObject(handle, INFINITE); }
00068 
00069     bool try_lock_mutex(void)
00070     { return WaitForSingleObject(handle, INFINITE)==WAIT_FAILED; }
00071 
00072     void unlock_mutex(void)
00073     { ReleaseMutex(handle); }
00074 };
00075 
00076 _ETL_END_NAMESPACE
00077 
00078 /* === E X T E R N S ======================================================= */
00079 
00080 /* === E N D =============================================================== */
00081 
00082 #endif

Generated on Sun Oct 28 06:22:06 2007 for ETL by  doxygen 1.5.3-20071008