Initial import
[sliver-openvswitch.git] / datapath / linux-2.4 / compat-2.4 / include / linux / mutex.h
1 #ifndef __LINUX_MUTEX_H
2 #define __LINUX_MUTEX_H
3
4 #include <asm/semaphore.h>
5
6 struct mutex {
7         struct semaphore sema;
8 };
9
10 #define mutex_init(mutex) init_MUTEX(&mutex->sema)
11 #define mutex_destroy(mutex) do { } while (0)
12
13 #define DEFINE_MUTEX(mutexname) \
14         struct mutex mutexname = { __MUTEX_INITIALIZER(mutexname.sema) }
15
16 /**
17  * mutex_is_locked - is the mutex locked
18  * @lock: the mutex to be queried
19  *
20  * Returns 1 if the mutex is locked, 0 if unlocked.
21  */
22 static inline int mutex_is_locked(struct mutex *lock)
23 {
24         return sem_getcount(&lock->sema) == 0;
25 }
26
27 /*
28  * See kernel/mutex.c for detailed documentation of these APIs.
29  * Also see Documentation/mutex-design.txt.
30  */
31 static inline void mutex_lock(struct mutex *lock)
32 {
33         down(&lock->sema);
34 }
35
36 static inline int mutex_lock_interruptible(struct mutex *lock)
37 {
38         return down_interruptible(&lock->sema);
39 }
40
41 #define mutex_lock_nested(lock, subclass) mutex_lock(lock)
42 #define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)
43
44 /*
45  * NOTE: mutex_trylock() follows the spin_trylock() convention,
46  *       not the down_trylock() convention!
47  */
48 static inline int mutex_trylock(struct mutex *lock)
49 {
50         return !down_trylock(&lock->sema);
51 }
52
53 static inline void mutex_unlock(struct mutex *lock)
54 {
55         up(&lock->sema);
56 }
57
58 #endif