1 #include <lib/base/elock.h>
4 void eLock::lock(int res)
8 pthread_mutex_lock(&mutex);
9 while ((counter+res)>max)
10 pthread_cond_wait(&cond, &mutex);
12 pthread_mutex_unlock(&mutex);
15 void eLock::unlock(int res)
19 pthread_mutex_lock(&mutex);
21 pthread_mutex_unlock(&mutex);
22 pthread_cond_signal(&cond);
25 eLock::eLock(int max): max(max)
27 pthread_mutex_init(&mutex, 0);
28 pthread_cond_init(&cond, 0);
35 pthread_mutex_destroy(&mutex);
36 pthread_cond_destroy(&cond);
39 eLocker::eLocker(eLock &lock, int res): lock(lock), res(res)
49 eSemaphore::eSemaphore()
52 pthread_mutex_init(&mutex, 0);
53 pthread_cond_init(&cond, 0);
56 eSemaphore::~eSemaphore()
58 pthread_mutex_destroy(&mutex);
59 pthread_cond_destroy(&cond);
62 int eSemaphore::down()
65 pthread_mutex_lock(&mutex);
67 pthread_cond_wait(&cond, &mutex);
70 pthread_mutex_unlock(&mutex);
71 return value_after_op;
74 int eSemaphore::decrement()
77 pthread_mutex_lock(&mutex);
80 pthread_mutex_unlock(&mutex);
81 pthread_cond_signal(&cond);
82 return value_after_op;
88 pthread_mutex_lock(&mutex);
91 pthread_mutex_unlock(&mutex);
92 pthread_cond_signal(&cond);
93 return value_after_op;
96 int eSemaphore::value()
99 pthread_mutex_lock(&mutex);
101 pthread_mutex_unlock(&mutex);
102 return value_after_op;