37 #ifndef NVWA_FAST_MUTEX_H
38 #define NVWA_FAST_MUTEX_H
43 # if !defined(_NOTHREADS)
44 # if !defined(NVWA_USE_CXX11_MUTEX) && HAVE_CXX11_MUTEX != 0 && \
45 !defined(_WIN32THREADS) && !defined(NVWA_WIN32THREADS) && \
46 !defined(NVWA_PTHREADS) && !defined(NVWA_NOTHREADS) && \
47 defined(_WIN32) && defined(_MT) && \
48 (!defined(_MSC_VER) || defined(_DLL))
58 # define NVWA_USE_CXX11_MUTEX 1
61 # if !defined(_WIN32THREADS) && \
62 (defined(_WIN32) && defined(_MT))
65 # define _WIN32THREADS
66 # elif !defined(_PTHREADS) && \
73 # ifndef NVWA_USE_CXX11_MUTEX
74 # if HAVE_CXX11_MUTEX != 0 && \
75 !defined(_NOTHREADS) && !defined(NVWA_NOTHREADS) && \
76 !defined(_PTHREADS) && !defined(NVWA_PTHREADS) && \
77 !defined(_WIN32THREADS) && !defined(NVWA_WIN32THREADS)
78 # define NVWA_USE_CXX11_MUTEX 1
80 # define NVWA_USE_CXX11_MUTEX 0
84 # if !defined(_PTHREADS) && !defined(_WIN32THREADS) && \
85 !defined(_NOTHREADS) && NVWA_USE_CXX11_MUTEX == 0
89 # if defined(_NOTHREADS)
90 # if defined(_PTHREADS) || defined(_WIN32THREADS) || \
91 NVWA_USE_CXX11_MUTEX != 0
93 # error "Cannot define multi-threaded mode with -D_NOTHREADS"
97 # if defined(__MINGW32__) && defined(_WIN32THREADS) && !defined(_MT)
98 # error "Be sure to specify -mthreads with -D_WIN32THREADS"
104 # if NVWA_USE_CXX11_MUTEX == 0 && \
105 !defined(NVWA_WIN32THREADS) && \
106 !defined(NVWA_PTHREADS) && \
107 !defined(NVWA_NOTHREADS)
110 # if defined(_WIN32THREADS)
111 # define NVWA_WIN32THREADS
112 # elif defined(_PTHREADS)
113 # define NVWA_PTHREADS
115 # define NVWA_NOTHREADS
119 # ifndef _FAST_MUTEX_CHECK_INITIALIZATION
128 # define _FAST_MUTEX_CHECK_INITIALIZATION 1
135 # define _FAST_MUTEX_ASSERT(_Expr, _Msg) \
137 fprintf(stderr, "fast_mutex::%s\n", _Msg); \
142 # define _FAST_MUTEX_ASSERT(_Expr, _Msg) \
146 # if NVWA_USE_CXX11_MUTEX != 0
153 # define __VOLATILE volatile
160 std::mutex _M_mtx_impl;
161 # if _FAST_MUTEX_CHECK_INITIALIZATION
173 # if _FAST_MUTEX_CHECK_INITIALIZATION
174 _M_initialized =
true;
180 # if _FAST_MUTEX_CHECK_INITIALIZATION
181 _M_initialized =
false;
186 # if _FAST_MUTEX_CHECK_INITIALIZATION
198 # if _FAST_MUTEX_CHECK_INITIALIZATION
206 _M_mtx_impl.unlock();
213 # elif defined(NVWA_PTHREADS)
214 # include <pthread.h>
220 # define __VOLATILE volatile
227 pthread_mutex_t _M_mtx_impl;
228 # if _FAST_MUTEX_CHECK_INITIALIZATION
240 ::pthread_mutex_init(&_M_mtx_impl,
_NULLPTR);
241 # if _FAST_MUTEX_CHECK_INITIALIZATION
242 _M_initialized =
true;
248 # if _FAST_MUTEX_CHECK_INITIALIZATION
249 _M_initialized =
false;
251 ::pthread_mutex_destroy(&_M_mtx_impl);
255 # if _FAST_MUTEX_CHECK_INITIALIZATION
259 ::pthread_mutex_lock(&_M_mtx_impl);
272 # if _FAST_MUTEX_CHECK_INITIALIZATION
280 ::pthread_mutex_unlock(&_M_mtx_impl);
287 # elif defined(NVWA_WIN32THREADS)
288 # ifndef WIN32_LEAN_AND_MEAN
289 # define WIN32_LEAN_AND_MEAN
291 # include <windows.h>
297 # define __VOLATILE volatile
304 CRITICAL_SECTION _M_mtx_impl;
305 # if _FAST_MUTEX_CHECK_INITIALIZATION
317 ::InitializeCriticalSection(&_M_mtx_impl);
318 # if _FAST_MUTEX_CHECK_INITIALIZATION
319 _M_initialized =
true;
325 # if _FAST_MUTEX_CHECK_INITIALIZATION
326 _M_initialized =
false;
328 ::DeleteCriticalSection(&_M_mtx_impl);
332 # if _FAST_MUTEX_CHECK_INITIALIZATION
336 ::EnterCriticalSection(&_M_mtx_impl);
344 # if _FAST_MUTEX_CHECK_INITIALIZATION
352 ::LeaveCriticalSection(&_M_mtx_impl);
359 # elif defined(NVWA_NOTHREADS)
#define NVWA_NAMESPACE_BEGIN
#define NVWA_NAMESPACE_END
fast_mutex_autolock(fast_mutex &mtx)
fast_mutex_autolock & operator=(const fast_mutex_autolock &)
fast_mutex_autolock(const fast_mutex_autolock &)
fast_mutex(const fast_mutex &)
fast_mutex & operator=(const fast_mutex &)
#define _FAST_MUTEX_ASSERT(_Expr, _Msg)