1 // Copyright (c) 1996 James Clark
2 // See the file copying.txt for copying permission.
5 #define Mutex_INCLUDED 1
12 // <windows.h> appears to turn these warnings back on
14 #pragma warning ( disable : 4237 )
18 namespace SP_NAMESPACE {
25 Lock(Mutex *mp) : mp_(mp) {
26 if (mp) ::EnterCriticalSection(&mp->cs_);
29 if (mp_) ::LeaveCriticalSection(&mp_->cs_);
35 ::InitializeCriticalSection(&cs_);
38 ::DeleteCriticalSection(&cs_);
49 #endif /* SP_MUTEX_WIN32 */
55 namespace SP_NAMESPACE {
62 #endif /* SP_MUTEX_MACH */
64 #ifdef SP_MUTEX_PTHREADS
66 // Support for pthreads on Linux.
67 // Written by Matthias Clasen <clasen@mathematik.uni-freiburg.de>
76 namespace SP_NAMESPACE {
82 // Lock serves to automatically unlock Mutex, however control leaves
83 // a block. Don't let any "warning: unused variable `class Mutex::Lock lock'"
84 // mislead you; hopefully your compiler won't optimise this away...
86 Lock(Mutex *mp) : mp_(mp) { if (mp_) pthread_mutex_lock (&mp_->cs_); }
87 ~Lock() { if (mp_) pthread_mutex_unlock(&mp_->cs_); }
91 Mutex() { pthread_mutex_init (&cs_, NULL); }
92 ~Mutex() { pthread_mutex_destroy (&cs_); }
102 #endif /* SP_MUTEX_PTHREADS */
107 namespace SP_NAMESPACE {
123 #endif /* not SP_MUTEX */
125 #endif /* not Mutex_INCLUDED */