-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mutex.h
70 lines (60 loc) · 1.34 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
//*****************************************************************************
//
// Copyright (C) 2001 Steve Connet. All rights reserved.
//
// Source File Name : Mutex.h
// Author : Steve Connet
//
// Version : $Id: Mutex.h,v 1.3 2015/03/14 23:44:56 clu Exp $
//
// File Overview : class for single locking mechanism and condition
//
// Revision History :
//
// $Log: Mutex.h,v $
// Revision 1.3 2015/03/14 23:44:56 clu
// astyle code formatter applied
//
// Revision 1.2 2002/01/11 03:41:49 sconnet
// *** empty log message ***
//
// Revision 1.1 2001/11/08 06:17:14 sconnet
// Initial revision
//
//
//*****************************************************************************
//#pragma interface
#ifndef __MUTEX_H_
#define __MUTEX_H_
#include <sys/time.h>
#include <pthread.h>
//namespace ConnetUtils
//{
class Mutex
{
public:
Mutex();
~Mutex();
void lock() {
pthread_mutex_lock(&mutex);
}
void unlock() {
pthread_mutex_unlock(&mutex);
}
bool trylock() {
return (0 == pthread_mutex_trylock(&mutex));
}
void reset() {
event = false;
}
void signal();
void broadcast();
void waitEvent();
bool waitEvent(int timeout /* ms */);
private:
bool event;
pthread_mutex_t mutex;
pthread_cond_t cond;
};
//}
#endif // __MUTEX_H_