fix locking in dvb file player
[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 public:
26         eSingleLock()
27         {
28                 pthread_mutex_init(&m_lock, 0);
29         }
30         ~eSingleLock()
31         {
32                 pthread_mutex_destroy(&m_lock);
33         }
34 };
35
36 class eSingleLocker
37 {
38         eSingleLock &m_lock;
39 public:
40         eSingleLocker(eSingleLock &m)
41                 : m_lock(m)
42         {
43                 pthread_mutex_lock(&m_lock.m_lock);
44         }
45         ~eSingleLocker()
46         {
47                 pthread_mutex_unlock(&m_lock.m_lock);
48         }
49 };
50
51 class eLock
52 {
53         pthread_mutex_t mutex;
54         pthread_cond_t cond;
55
56         int pid;
57         int counter, max;
58 public:
59         void lock(int res=100);
60         void unlock(int res=100);
61
62         eLock(int max=100);
63         ~eLock();
64 };
65
66 class eLocker
67 {
68         eLock &lock;
69         int res;
70 public:
71         eLocker(eLock &lock, int res=100);
72         ~eLocker();
73 };
74
75 class eSemaphore
76 {
77         int v;
78         pthread_mutex_t mutex;
79         pthread_cond_t cond;
80 public:
81         eSemaphore();
82         ~eSemaphore();
83         
84         int down();
85         int decrement();
86         int up();
87         int value();
88 };
89
90 #endif