-
Notifications
You must be signed in to change notification settings - Fork 1
/
mutex.h
47 lines (40 loc) · 1.08 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
#ifndef MUTEX_H
#define MUTEX_H
#include <pthread.h>
namespace PThreads
{
/**
* Wrapper class for a pthread_mutex.
* Wrapper class around a pthread mutex. Creates the mutex and provides
* helper methods for working with it in an object oriented manner.
*/
class Mutex
{
public:
/**
* Default Constructor.
* Initializes the internal pthread mutex.
*/
Mutex();
/**
* Default Destructor.
* Destroys the internal pthread mutex.
*/
virtual ~Mutex();
/**
* Lock the mutex.
* Locks the mutex to prevent more than a single thread from accessing
* some critical section. Make sure to call unlock!
*/
virtual void lock();
/**
* Unlock the mutex.
* Unlocks the mutex so that other threads can access the critical
* section that the lock method and this method protect.
*/
virtual void unlock();
private:
pthread_mutex_t _mutex;
};
}
#endif