Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * RT Mutexes: blocking mutual exclusion locks with PI support |
| 3 | * |
| 4 | * started by Ingo Molnar and Thomas Gleixner: |
| 5 | * |
| 6 | * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com> |
| 7 | * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com> |
| 8 | * |
| 9 | * This file contains the public data structure and API definitions. |
| 10 | */ |
| 11 | |
| 12 | #ifndef __LINUX_RT_MUTEX_H |
| 13 | #define __LINUX_RT_MUTEX_H |
| 14 | |
| 15 | #include <linux/linkage.h> |
| 16 | #include <linux/plist.h> |
| 17 | #include <linux/spinlock_types.h> |
| 18 | |
Dave Young | 4f0e056 | 2010-03-10 15:24:09 -0800 | [diff] [blame] | 19 | extern int max_lock_depth; /* for sysctl */ |
| 20 | |
Robert P. J. Day | 45f8bde | 2007-01-26 00:57:09 -0800 | [diff] [blame] | 21 | /** |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 22 | * The rt_mutex structure |
| 23 | * |
| 24 | * @wait_lock: spinlock to protect the structure |
| 25 | * @wait_list: pilist head to enqueue waiters in priority order |
| 26 | * @owner: the mutex owner |
| 27 | */ |
| 28 | struct rt_mutex { |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 29 | raw_spinlock_t wait_lock; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 30 | struct plist_head wait_list; |
| 31 | struct task_struct *owner; |
| 32 | #ifdef CONFIG_DEBUG_RT_MUTEXES |
| 33 | int save_state; |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 34 | const char *name, *file; |
| 35 | int line; |
| 36 | void *magic; |
| 37 | #endif |
| 38 | }; |
| 39 | |
| 40 | struct rt_mutex_waiter; |
| 41 | struct hrtimer_sleeper; |
| 42 | |
| 43 | #ifdef CONFIG_DEBUG_RT_MUTEXES |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 44 | extern int rt_mutex_debug_check_no_locks_freed(const void *from, |
| 45 | unsigned long len); |
| 46 | extern void rt_mutex_debug_check_no_locks_held(struct task_struct *task); |
| 47 | #else |
| 48 | static inline int rt_mutex_debug_check_no_locks_freed(const void *from, |
| 49 | unsigned long len) |
| 50 | { |
| 51 | return 0; |
| 52 | } |
| 53 | # define rt_mutex_debug_check_no_locks_held(task) do { } while (0) |
| 54 | #endif |
| 55 | |
| 56 | #ifdef CONFIG_DEBUG_RT_MUTEXES |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 57 | # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \ |
| 58 | , .name = #mutexname, .file = __FILE__, .line = __LINE__ |
Harvey Harrison | d5c003b | 2008-10-15 22:01:24 -0700 | [diff] [blame] | 59 | # define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 60 | extern void rt_mutex_debug_task_free(struct task_struct *tsk); |
| 61 | #else |
| 62 | # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) |
| 63 | # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL) |
Ingo Molnar | e7eebaf | 2006-06-27 02:54:55 -0700 | [diff] [blame] | 64 | # define rt_mutex_debug_task_free(t) do { } while (0) |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 65 | #endif |
| 66 | |
| 67 | #define __RT_MUTEX_INITIALIZER(mutexname) \ |
Thomas Gleixner | d209d74 | 2009-11-17 18:22:11 +0100 | [diff] [blame] | 68 | { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ |
Dima Zavin | 732375c | 2011-07-07 17:27:59 -0700 | [diff] [blame] | 69 | , .wait_list = PLIST_HEAD_INIT(mutexname.wait_list) \ |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 70 | , .owner = NULL \ |
| 71 | __DEBUG_RT_MUTEX_INITIALIZER(mutexname)} |
| 72 | |
| 73 | #define DEFINE_RT_MUTEX(mutexname) \ |
| 74 | struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) |
| 75 | |
Robert P. J. Day | 45f8bde | 2007-01-26 00:57:09 -0800 | [diff] [blame] | 76 | /** |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 77 | * rt_mutex_is_locked - is the mutex locked |
| 78 | * @lock: the mutex to be queried |
| 79 | * |
| 80 | * Returns 1 if the mutex is locked, 0 if unlocked. |
| 81 | */ |
| 82 | static inline int rt_mutex_is_locked(struct rt_mutex *lock) |
| 83 | { |
| 84 | return lock->owner != NULL; |
| 85 | } |
| 86 | |
| 87 | extern void __rt_mutex_init(struct rt_mutex *lock, const char *name); |
| 88 | extern void rt_mutex_destroy(struct rt_mutex *lock); |
| 89 | |
| 90 | extern void rt_mutex_lock(struct rt_mutex *lock); |
| 91 | extern int rt_mutex_lock_interruptible(struct rt_mutex *lock, |
| 92 | int detect_deadlock); |
| 93 | extern int rt_mutex_timed_lock(struct rt_mutex *lock, |
| 94 | struct hrtimer_sleeper *timeout, |
| 95 | int detect_deadlock); |
| 96 | |
| 97 | extern int rt_mutex_trylock(struct rt_mutex *lock); |
| 98 | |
| 99 | extern void rt_mutex_unlock(struct rt_mutex *lock); |
| 100 | |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 101 | #ifdef CONFIG_RT_MUTEXES |
| 102 | # define INIT_RT_MUTEXES(tsk) \ |
Dima Zavin | 732375c | 2011-07-07 17:27:59 -0700 | [diff] [blame] | 103 | .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters), \ |
Ingo Molnar | 23f78d4a | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 104 | INIT_RT_MUTEX_DEBUG(tsk) |
| 105 | #else |
| 106 | # define INIT_RT_MUTEXES(tsk) |
| 107 | #endif |
| 108 | |
| 109 | #endif |