1 #ifndef __LINUX_MUTEX_H
2 #define __LINUX_MUTEX_H
4 #include <asm/semaphore.h>
10 #define mutex_init(mutex) init_MUTEX(&mutex->sema)
11 #define mutex_destroy(mutex) do { } while (0)
13 #define DEFINE_MUTEX(mutexname) \
14 struct mutex mutexname = { __MUTEX_INITIALIZER(mutexname.sema) }
17 * mutex_is_locked - is the mutex locked
18 * @lock: the mutex to be queried
20 * Returns 1 if the mutex is locked, 0 if unlocked.
22 static inline int mutex_is_locked(struct mutex *lock)
24 return sem_getcount(&lock->sema) == 0;
28 * See kernel/mutex.c for detailed documentation of these APIs.
29 * Also see Documentation/mutex-design.txt.
31 static inline void mutex_lock(struct mutex *lock)
36 static inline int mutex_lock_interruptible(struct mutex *lock)
38 return down_interruptible(&lock->sema);
41 #define mutex_lock_nested(lock, subclass) mutex_lock(lock)
42 #define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)
45 * NOTE: mutex_trylock() follows the spin_trylock() convention,
46 * not the down_trylock() convention!
48 static inline int mutex_trylock(struct mutex *lock)
50 return !down_trylock(&lock->sema);
53 static inline void mutex_unlock(struct mutex *lock)