prevent this from happening again
[enigma2.git] / lib / base / elock.h
1 #ifndef __elock_h
2 #define __elock_h
3
4 #include <pthread.h>
5
6 class singleLock
7 {
8         pthread_mutex_t &lock;
9 public:
10         singleLock(pthread_mutex_t &m )
11                 :lock(m)
12         {
13                 pthread_mutex_lock(&lock);
14         }
15         ~singleLock()
16         {
17                 pthread_mutex_unlock(&lock);
18         }
19 };
20
21 class eSingleLock
22 {
23         friend class eSingleLocker;
24         pthread_mutex_t m_lock;
25         eSingleLock(eSingleLock &);
26 public:
27         eSingleLock()
28         {
29                 pthread_mutex_init(&m_lock, 0);
30         }
31         ~eSingleLock()
32         {
33                 pthread_mutex_destroy(&m_lock);
34         }
35 };
36
37 class eSingleLocker
38 {
39         eSingleLock &m_lock;
40 public:
41         eSingleLocker(eSingleLock &m)
42                 : m_lock(m)
43         {
44                 pthread_mutex_lock(&m_lock.m_lock);
45         }
46         ~eSingleLocker()
47         {
48                 pthread_mutex_unlock(&m_lock.m_lock);
49         }
50 };
51
52 class eLock
53 {
54         pthread_mutex_t mutex;
55         pthread_cond_t cond;
56
57         int pid;
58         int counter, max;
59 public:
60         void lock(int res=100);
61         void unlock(int res=100);
62
63         eLock(int max=100);
64         ~eLock();
65 };
66
67 class eLocker
68 {
69         eLock &lock;
70         int res;
71 public:
72         eLocker(eLock &lock, int res=100);
73         ~eLocker();
74 };
75
76 class eSemaphore
77 {
78         int v;
79         pthread_mutex_t mutex;
80         pthread_cond_t cond;
81 public:
82         eSemaphore();
83         ~eSemaphore();
84         
85         int down();
86         int decrement();
87         int up();
88         int value();
89 };
90
91 #endif