Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions
mutex.h File Reference
#include <linux/list.h>
#include <linux/spinlock_types.h>
#include <linux/linkage.h>
#include <linux/lockdep.h>
#include <linux/atomic.h>

Go to the source code of this file.

Data Structures

struct  mutex
 
struct  mutex_waiter
 

Macros

#define __DEBUG_MUTEX_INITIALIZER(lockname)
 
#define mutex_init(mutex)
 
#define __DEP_MAP_MUTEX_INITIALIZER(lockname)
 
#define __MUTEX_INITIALIZER(lockname)
 
#define DEFINE_MUTEX(mutexname)   struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
 
#define mutex_lock_nested(lock, subclass)   mutex_lock(lock)
 
#define mutex_lock_interruptible_nested(lock, subclass)   mutex_lock_interruptible(lock)
 
#define mutex_lock_killable_nested(lock, subclass)   mutex_lock_killable(lock)
 
#define mutex_lock_nest_lock(lock, nest_lock)   mutex_lock(lock)
 
#define arch_mutex_cpu_relax()   cpu_relax()
 

Functions

void __mutex_init (struct mutex *lock, const char *name, struct lock_class_key *key)
 
void mutex_lock (struct mutex *lock)
 
int __must_check mutex_lock_interruptible (struct mutex *lock)
 
int __must_check mutex_lock_killable (struct mutex *lock)
 
int mutex_trylock (struct mutex *lock)
 
void mutex_unlock (struct mutex *lock)
 
int atomic_dec_and_mutex_lock (atomic_t *cnt, struct mutex *lock)
 

Macro Definition Documentation

#define __DEBUG_MUTEX_INITIALIZER (   lockname)

Definition at line 80 of file mutex.h.

#define __DEP_MAP_MUTEX_INITIALIZER (   lockname)

Definition at line 102 of file mutex.h.

#define __MUTEX_INITIALIZER (   lockname)
Value:
{ .count = ATOMIC_INIT(1) \
, .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
, .wait_list = LIST_HEAD_INIT(lockname.wait_list) \
__DEBUG_MUTEX_INITIALIZER(lockname) \
__DEP_MAP_MUTEX_INITIALIZER(lockname) }

Definition at line 105 of file mutex.h.

#define arch_mutex_cpu_relax ( )    cpu_relax()

Definition at line 173 of file mutex.h.

#define DEFINE_MUTEX (   mutexname)    struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)

Definition at line 112 of file mutex.h.

#define mutex_init (   mutex)
Value:
do { \
static struct lock_class_key __key; \
__mutex_init((mutex), #mutex, &__key); \
} while (0)

mutex_init - initialize the mutex : the mutex to be initialized

Initialize the mutex to unlocked state.

It is not allowed to initialize an already locked mutex.

Definition at line 89 of file mutex.h.

#define mutex_lock_interruptible_nested (   lock,
  subclass 
)    mutex_lock_interruptible(lock)

Definition at line 157 of file mutex.h.

#define mutex_lock_killable_nested (   lock,
  subclass 
)    mutex_lock_killable(lock)

Definition at line 158 of file mutex.h.

#define mutex_lock_nest_lock (   lock,
  nest_lock 
)    mutex_lock(lock)

Definition at line 159 of file mutex.h.

#define mutex_lock_nested (   lock,
  subclass 
)    mutex_lock(lock)

Definition at line 156 of file mutex.h.

Function Documentation

void __mutex_init ( struct mutex lock,
const char name,
struct lock_class_key key 
)

Definition at line 40 of file mutex.c.

int atomic_dec_and_mutex_lock ( atomic_t cnt,
struct mutex lock 
)

atomic_dec_and_mutex_lock - return holding mutex if we dec to 0 : the atomic which we are to dec : the mutex to return holding if we dec to 0

return true and hold lock if we dec to 0, return false otherwise

Definition at line 483 of file mutex.c.

void mutex_lock ( struct mutex lock)

mutex_lock - acquire the mutex : the mutex to be acquired

Lock the mutex exclusively for this task. If the mutex is not available right now, it will sleep until it can get it.

The mutex must later on be released by the same task that acquired it. Recursive locking is not allowed. The task may not exit without first unlocking the mutex. Also, kernel memory where the mutex resides mutex must not be freed with the mutex still locked. The mutex must first be initialized (or statically defined) before it can be locked. memset()-ing the mutex to 0 is not allowed.

( The CONFIG_DEBUG_MUTEXES .config option turns on debugging checks that will enforce the restrictions and will also do deadlock debugging. )

This function is similar to (but not equivalent to) down().

Definition at line 83 of file mutex.c.

int __must_check mutex_lock_interruptible ( struct mutex lock)

mutex_lock_interruptible - acquire the mutex, interruptible : the mutex to be acquired

Lock the mutex like mutex_lock(), and return 0 if the mutex has been acquired or sleep until the mutex becomes available. If a signal arrives while waiting for the lock then this function returns -EINTR.

This function is similar to (but not equivalent to) down_interruptible().

Definition at line 369 of file mutex.c.

int __must_check mutex_lock_killable ( struct mutex lock)

Definition at line 384 of file mutex.c.

int mutex_trylock ( struct mutex lock)

mutex_trylock - try to acquire the mutex, without waiting : the mutex to be acquired

Try to acquire the mutex atomically. Returns 1 if the mutex has been acquired successfully, and 0 on contention.

NOTE: this function follows the spin_trylock() convention, so it is negated from the down_trylock() return values! Be careful about this when converting semaphore users to mutexes.

This function must not be used in interrupt context. The mutex must be released by the same task that acquired it.

Definition at line 464 of file mutex.c.

void mutex_unlock ( struct mutex lock)

mutex_unlock - release the mutex : the mutex to be released

Unlock a mutex that has been locked by this task previously.

This function must not be used in interrupt context. Unlocking of a not locked mutex is not allowed.

This function is similar to (but not equivalent to) up().

Definition at line 110 of file mutex.c.