Mercurial > hg > apm2s
comparison stk/include/Mutex.h @ 0:4606bd505630 tip
first import
author | Fiore Martin <f.martin@qmul.ac.uk> |
---|---|
date | Sat, 13 Jun 2015 15:08:10 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4606bd505630 |
---|---|
1 #ifndef STK_MUTEX_H | |
2 #define STK_MUTEX_H | |
3 | |
4 #include "Stk.h" | |
5 | |
6 #if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__)) | |
7 | |
8 #include <pthread.h> | |
9 typedef pthread_mutex_t MUTEX; | |
10 typedef pthread_cond_t CONDITION; | |
11 | |
12 #elif defined(__OS_WINDOWS__) | |
13 | |
14 #include <windows.h> | |
15 #include <process.h> | |
16 typedef CRITICAL_SECTION MUTEX; | |
17 typedef HANDLE CONDITION; | |
18 | |
19 #endif | |
20 | |
21 namespace stk { | |
22 | |
23 /***************************************************/ | |
24 /*! \class Mutex | |
25 \brief STK mutex class. | |
26 | |
27 This class provides a uniform interface for | |
28 cross-platform mutex use. On Linux and IRIX | |
29 systems, the pthread library is used. Under | |
30 Windows, critical sections are used. | |
31 | |
32 by Perry R. Cook and Gary P. Scavone, 1995--2014. | |
33 */ | |
34 /***************************************************/ | |
35 | |
36 class Mutex : public Stk | |
37 { | |
38 public: | |
39 //! Default constructor. | |
40 Mutex(); | |
41 | |
42 //! Class destructor. | |
43 ~Mutex(); | |
44 | |
45 //! Lock the mutex. | |
46 void lock(void); | |
47 | |
48 //! Unlock the mutex. | |
49 void unlock(void); | |
50 | |
51 //! Wait indefinitely on the mutex condition variable. | |
52 /*! | |
53 The mutex must be locked before calling this function, and then | |
54 subsequently unlocked after this function returns. | |
55 */ | |
56 void wait(void); | |
57 | |
58 //! Signal the condition variable. | |
59 /*! | |
60 The mutex must be locked before calling this function, and then | |
61 subsequently unlocked after this function returns. | |
62 */ | |
63 void signal(void); | |
64 | |
65 protected: | |
66 | |
67 MUTEX mutex_; | |
68 CONDITION condition_; | |
69 | |
70 }; | |
71 | |
72 } // stk namespace | |
73 | |
74 #endif |