1 /*! ========================================================================
2 ** Extended Template and Library
3 ** Mutex Abstraction Class Implementation
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** This is an internal header file, included by other ETL headers.
21 ** You should not attempt to use it directly.
23 ** ========================================================================= */
25 /* === S T A R T =========================================================== */
27 #ifndef __ETL__MUTEX_WIN32_H_
28 #define __ETL__MUTEX_WIN32_H_
30 /* === H E A D E R S ======================================================= */
33 // extern HANDLE CreateMutex(NULL, FALSE, NULL);
34 // extern CloseHandle(handle);
35 // extern WaitForSingleObject(handle, INFINITE);
36 // extern ReleaseMutex(handle);
38 /* === M A C R O S ========================================================= */
41 /* === C L A S S E S & S T R U C T S ======================================= */
51 { handle = CreateMutex(NULL, FALSE, NULL); }
54 { CloseHandle(handle); }
56 //! Exception-safe mutex lock class
61 lock(mutex &x):_mtx(&x) { _mtx->lock_mutex(); }
62 ~lock() { _mtx->unlock_mutex(); }
63 mutex &get() { return *_mtx; }
67 { WaitForSingleObject(handle, INFINITE); }
69 bool try_lock_mutex(void)
70 { return WaitForSingleObject(handle, INFINITE)==WAIT_FAILED; }
72 void unlock_mutex(void)
73 { ReleaseMutex(handle); }
78 /* === E X T E R N S ======================================================= */
80 /* === E N D =============================================================== */