1 #ifndef __LINUX_MUTEX_WRAPPER_H
2 #define __LINUX_MUTEX_WRAPPER_H
5 #include <linux/version.h>
6 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
8 #include <asm/semaphore.h>
11 struct semaphore sema;
14 #define mutex_init(mutex) init_MUTEX(&(mutex)->sema)
15 #define mutex_destroy(mutex) do { } while (0)
17 #define __MUTEX_INITIALIZER(name) \
18 __SEMAPHORE_INITIALIZER(name,1)
20 #define DEFINE_MUTEX(mutexname) \
21 struct mutex mutexname = { __MUTEX_INITIALIZER(mutexname.sema) }
24 * See kernel/mutex.c for detailed documentation of these APIs.
25 * Also see Documentation/mutex-design.txt.
27 static inline void mutex_lock(struct mutex *lock)
32 static inline int mutex_lock_interruptible(struct mutex *lock)
34 return down_interruptible(&lock->sema);
37 #define mutex_lock_nested(lock, subclass) mutex_lock(lock)
38 #define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)
41 * NOTE: mutex_trylock() follows the spin_trylock() convention,
42 * not the down_trylock() convention!
44 static inline int mutex_trylock(struct mutex *lock)
46 return !down_trylock(&lock->sema);
49 static inline void mutex_unlock(struct mutex *lock)
55 #include_next <linux/mutex.h>
57 #endif /* linux version < 2.6.16 */