comparison Mutex.h @ 3:134313c59d82

* Add global mutex to PyPlugin -- all plugin method calls are strictly serialised in order to avoid problems with Python interpreter's lack of thread safety.
author cannam
date Fri, 14 Mar 2008 12:02:15 +0000
parents
children
comparison
equal deleted inserted replaced
2:211ebe55d521 3:134313c59d82
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Basic cross-platform mutex abstraction class.
5 This file copyright 2007 Chris Cannam.
6 */
7
8 #ifndef _MUTEX_H_
9 #define _MUTEX_H_
10
11 #ifdef _WIN32
12 #include <windows.h>
13 #else
14 #include <pthread.h>
15 #endif
16
17 class Mutex
18 {
19 public:
20 Mutex();
21 ~Mutex();
22
23 void lock();
24 void unlock();
25 bool trylock();
26
27 private:
28 #ifdef _WIN32
29 HANDLE m_mutex;
30 #ifndef NO_THREAD_CHECKS
31 DWORD m_lockedBy;
32 #endif
33 #else
34 pthread_mutex_t m_mutex;
35 #ifndef NO_THREAD_CHECKS
36 pthread_t m_lockedBy;
37 bool m_locked;
38 #endif
39 #endif
40 };
41
42 class MutexLocker
43 {
44 public:
45 MutexLocker(Mutex *);
46 ~MutexLocker();
47
48 private:
49 Mutex *m_mutex;
50 };
51
52 #endif
53