From 8a6d48c0542876eb3acfc0970c0ab7872db08d5f Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Sun, 6 Dec 2009 05:26:23 +0100 Subject: check in the original version of dde linux26. --- libdde_linux26/contrib/include/linux/mutex.h | 153 +++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 libdde_linux26/contrib/include/linux/mutex.h (limited to 'libdde_linux26/contrib/include/linux/mutex.h') diff --git a/libdde_linux26/contrib/include/linux/mutex.h b/libdde_linux26/contrib/include/linux/mutex.h new file mode 100644 index 00000000..7a0e5c4f --- /dev/null +++ b/libdde_linux26/contrib/include/linux/mutex.h @@ -0,0 +1,153 @@ +/* + * Mutexes: blocking mutual exclusion locks + * + * started by Ingo Molnar: + * + * Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar + * + * This file contains the main data structure and API definitions. + */ +#ifndef __LINUX_MUTEX_H +#define __LINUX_MUTEX_H + +#include +#include +#include +#include + +#include + +/* + * Simple, straightforward mutexes with strict semantics: + * + * - only one task can hold the mutex at a time + * - only the owner can unlock the mutex + * - multiple unlocks are not permitted + * - recursive locking is not permitted + * - a mutex object must be initialized via the API + * - a mutex object must not be initialized via memset or copying + * - task may not exit with mutex held + * - memory areas where held locks reside must not be freed + * - held mutexes must not be reinitialized + * - mutexes may not be used in hardware or software interrupt + * contexts such as tasklets and timers + * + * These semantics are fully enforced when DEBUG_MUTEXES is + * enabled. Furthermore, besides enforcing the above rules, the mutex + * debugging code also implements a number of additional features + * that make lock debugging easier and faster: + * + * - uses symbolic names of mutexes, whenever they are printed in debug output + * - point-of-acquire tracking, symbolic lookup of function names + * - list of all locks held in the system, printout of them + * - owner tracking + * - detects self-recursing locks and prints out all relevant info + * - detects multi-task circular deadlocks and prints out all affected + * locks and tasks (and only those tasks) + */ +struct mutex { + /* 1: unlocked, 0: locked, negative: locked, possible waiters */ + atomic_t count; + spinlock_t wait_lock; + struct list_head wait_list; +#ifdef CONFIG_DEBUG_MUTEXES + struct thread_info *owner; + const char *name; + void *magic; +#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC + struct lockdep_map dep_map; +#endif +}; + +/* + * This is the control structure for tasks blocked on mutex, + * which resides on the blocked task's kernel stack: + */ +struct mutex_waiter { + struct list_head list; + struct task_struct *task; +#ifdef CONFIG_DEBUG_MUTEXES + struct mutex *lock; + void *magic; +#endif +}; + +#ifdef CONFIG_DEBUG_MUTEXES +# include +#else +# define __DEBUG_MUTEX_INITIALIZER(lockname) +# define mutex_init(mutex) \ +do { \ + static struct lock_class_key __key; \ + \ + __mutex_init((mutex), #mutex, &__key); \ +} while (0) +# define mutex_destroy(mutex) do { } while (0) +#endif + +#ifdef CONFIG_DEBUG_LOCK_ALLOC +# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \ + , .dep_map = { .name = #lockname } +#else +# define __DEP_MAP_MUTEX_INITIALIZER(lockname) +#endif + +#define __MUTEX_INITIALIZER(lockname) \ + { .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) } + +#define DEFINE_MUTEX(mutexname) \ + struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) + +extern void __mutex_init(struct mutex *lock, const char *name, + struct lock_class_key *key); + +/** + * mutex_is_locked - is the mutex locked + * @lock: the mutex to be queried + * + * Returns 1 if the mutex is locked, 0 if unlocked. + */ +static inline int mutex_is_locked(struct mutex *lock) +{ + return atomic_read(&lock->count) != 1; +} + +/* + * See kernel/mutex.c for detailed documentation of these APIs. + * Also see Documentation/mutex-design.txt. + */ +#ifdef CONFIG_DEBUG_LOCK_ALLOC +extern void mutex_lock_nested(struct mutex *lock, unsigned int subclass); +extern int __must_check mutex_lock_interruptible_nested(struct mutex *lock, + unsigned int subclass); +extern int __must_check mutex_lock_killable_nested(struct mutex *lock, + unsigned int subclass); + +#define mutex_lock(lock) mutex_lock_nested(lock, 0) +#define mutex_lock_interruptible(lock) mutex_lock_interruptible_nested(lock, 0) +#define mutex_lock_killable(lock) mutex_lock_killable_nested(lock, 0) +#else +extern void mutex_lock(struct mutex *lock); +extern int __must_check mutex_lock_interruptible(struct mutex *lock); +extern int __must_check mutex_lock_killable(struct mutex *lock); + +# 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) +#endif + +/* + * NOTE: mutex_trylock() follows the spin_trylock() convention, + * not the down_trylock() convention! + * + * Returns 1 if the mutex has been acquired successfully, and 0 on contention. + */ +extern int mutex_trylock(struct mutex *lock); +extern void mutex_unlock(struct mutex *lock); + +#endif -- cgit v1.2.3 From 76abb76f59341a7ef75566e3f9cb59dea3648b4a Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Wed, 13 Jan 2010 12:06:56 +0100 Subject: hide __mutex_init because of name conflict with libc. --- libdde_linux26/contrib/include/linux/mutex.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libdde_linux26/contrib/include/linux/mutex.h') diff --git a/libdde_linux26/contrib/include/linux/mutex.h b/libdde_linux26/contrib/include/linux/mutex.h index 7a0e5c4f..cf30c48c 100644 --- a/libdde_linux26/contrib/include/linux/mutex.h +++ b/libdde_linux26/contrib/include/linux/mutex.h @@ -102,8 +102,9 @@ do { \ #define DEFINE_MUTEX(mutexname) \ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) +#define HIDDEN __attribute__ ((visibility("hidden"))) -extern void __mutex_init(struct mutex *lock, const char *name, +extern void HIDDEN __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key); /** -- cgit v1.2.3 From 51299b970600d28df634708557f80df3526014ae Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Sat, 16 Jan 2010 00:08:24 +0100 Subject: rename __mutex_init to avoid the name conflict. --- libdde_linux26/contrib/include/linux/mutex-debug.h | 2 +- libdde_linux26/contrib/include/linux/mutex.h | 6 +++--- libdde_linux26/contrib/kernel/mutex.c | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'libdde_linux26/contrib/include/linux/mutex.h') diff --git a/libdde_linux26/contrib/include/linux/mutex-debug.h b/libdde_linux26/contrib/include/linux/mutex-debug.h index 731d77d6..4382d53b 100644 --- a/libdde_linux26/contrib/include/linux/mutex-debug.h +++ b/libdde_linux26/contrib/include/linux/mutex-debug.h @@ -10,7 +10,7 @@ #define __DEBUG_MUTEX_INITIALIZER(lockname) \ , .magic = &lockname - +#define __mutex_init __dde_mutex_init #define mutex_init(mutex) \ do { \ static struct lock_class_key __key; \ diff --git a/libdde_linux26/contrib/include/linux/mutex.h b/libdde_linux26/contrib/include/linux/mutex.h index cf30c48c..360dd9e3 100644 --- a/libdde_linux26/contrib/include/linux/mutex.h +++ b/libdde_linux26/contrib/include/linux/mutex.h @@ -77,6 +77,7 @@ struct mutex_waiter { # include #else # define __DEBUG_MUTEX_INITIALIZER(lockname) +#define __mutex_init __dde_mutex_init # define mutex_init(mutex) \ do { \ static struct lock_class_key __key; \ @@ -102,10 +103,9 @@ do { \ #define DEFINE_MUTEX(mutexname) \ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) -#define HIDDEN __attribute__ ((visibility("hidden"))) -extern void HIDDEN __mutex_init(struct mutex *lock, const char *name, - struct lock_class_key *key); +extern void __dde_mutex_init(struct mutex *lock, const char *name, + struct lock_class_key *key); /** * mutex_is_locked - is the mutex locked diff --git a/libdde_linux26/contrib/kernel/mutex.c b/libdde_linux26/contrib/kernel/mutex.c index 4f45d4b6..0173f29a 100644 --- a/libdde_linux26/contrib/kernel/mutex.c +++ b/libdde_linux26/contrib/kernel/mutex.c @@ -41,7 +41,8 @@ * It is not allowed to initialize an already locked mutex. */ void -__mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key) +__dde_mutex_init(struct mutex *lock, const char *name, + struct lock_class_key *key) { atomic_set(&lock->count, 1); spin_lock_init(&lock->wait_lock); @@ -50,7 +51,7 @@ __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key) debug_mutex_init(lock, name, key); } -EXPORT_SYMBOL(__mutex_init); +EXPORT_SYMBOL(__dde_mutex_init); #ifndef CONFIG_DEBUG_LOCK_ALLOC /* -- cgit v1.2.3