Commit | Line | Data |
---|---|---|
7753f181 DD |
1 | |
2 | #include <pthread.h> | |
3 | ||
4 | #ifndef __WIFI_HAL_SYNC_H__ | |
5 | #define __WIFI_HAL_SYNC_H__ | |
6 | ||
7 | class Mutex | |
8 | { | |
9 | private: | |
10 | pthread_mutex_t mMutex; | |
11 | public: | |
12 | Mutex() { | |
13 | pthread_mutex_init(&mMutex, NULL); | |
14 | } | |
15 | ~Mutex() { | |
16 | pthread_mutex_destroy(&mMutex); | |
17 | } | |
18 | int tryLock() { | |
19 | return pthread_mutex_trylock(&mMutex); | |
20 | } | |
21 | int lock() { | |
22 | return pthread_mutex_lock(&mMutex); | |
23 | } | |
24 | void unlock() { | |
25 | pthread_mutex_unlock(&mMutex); | |
26 | } | |
27 | }; | |
28 | ||
29 | class Condition | |
30 | { | |
31 | private: | |
32 | pthread_cond_t mCondition; | |
33 | pthread_mutex_t mMutex; | |
34 | ||
35 | public: | |
36 | Condition() { | |
37 | pthread_mutex_init(&mMutex, NULL); | |
38 | pthread_cond_init(&mCondition, NULL); | |
39 | } | |
40 | ~Condition() { | |
41 | pthread_cond_destroy(&mCondition); | |
42 | pthread_mutex_destroy(&mMutex); | |
43 | } | |
44 | ||
45 | int wait() { | |
46 | return pthread_cond_wait(&mCondition, &mMutex); | |
47 | } | |
48 | ||
49 | void signal() { | |
50 | pthread_cond_signal(&mCondition); | |
51 | } | |
52 | }; | |
53 | ||
b2737ea7 | 54 | #endif |