aboutsummaryrefslogtreecommitdiff
path: root/lib/base/elock.h
blob: 6a47f8c9cec9f7541f544d9f349553f8c740bec8 (plain)
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
#ifndef __elock_h
#define __elock_h

#include <pthread.h>

class singleLock
{
	pthread_mutex_t &lock;
public:
	singleLock( pthread_mutex_t &m )
		:lock(m)
	{
		pthread_mutex_lock(&lock);
	}
	~singleLock()
	{
		pthread_mutex_unlock(&lock);
	}
};

class eLock
{
	pthread_mutex_t mutex;
	pthread_cond_t cond;

	int pid;
	int counter, max;
public:
	void lock(int res=100);
	void unlock(int res=100);

	eLock(int max=100);
	~eLock();
};

class eLocker
{
	eLock &lock;
	int res;
public:
	eLocker(eLock &lock, int res=100);
	~eLocker();
};

class eSemaphore
{
	int v;
	pthread_mutex_t mutex;
	pthread_cond_t cond;
public:
	eSemaphore();
	~eSemaphore();
	
	int down();
	int decrement();
	int up();
	int value();
};

#endif