-
Notifications
You must be signed in to change notification settings - Fork 185
/
Mutex.h
74 lines (53 loc) · 1.45 KB
/
Mutex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef STK_MUTEX_H
#define STK_MUTEX_H
#include "Stk.h"
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__))
#include <pthread.h>
typedef pthread_mutex_t MUTEX;
typedef pthread_cond_t CONDITION;
#elif defined(__OS_WINDOWS__)
#include <windows.h>
#include <process.h>
typedef CRITICAL_SECTION MUTEX;
typedef HANDLE CONDITION;
#endif
namespace stk {
/***************************************************/
/*! \class Mutex
\brief STK mutex class.
This class provides a uniform interface for
cross-platform mutex use. On Linux and IRIX
systems, the pthread library is used. Under
Windows, critical sections are used.
by Perry R. Cook and Gary P. Scavone, 1995--2023.
*/
/***************************************************/
class Mutex : public Stk
{
public:
//! Default constructor.
Mutex();
//! Class destructor.
~Mutex();
//! Lock the mutex.
void lock(void);
//! Unlock the mutex.
void unlock(void);
//! Wait indefinitely on the mutex condition variable.
/*!
The mutex must be locked before calling this function, and then
subsequently unlocked after this function returns.
*/
void wait(void);
//! Signal the condition variable.
/*!
The mutex must be locked before calling this function, and then
subsequently unlocked after this function returns.
*/
void signal(void);
protected:
MUTEX mutex_;
CONDITION condition_;
};
} // stk namespace
#endif