2 * RT Mutexes: blocking mutual exclusion locks with PI support
4 * started by Ingo Molnar and Thomas Gleixner:
6 * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
7 * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
9 * This file contains the public data structure and API definitions.
12 #ifndef __LINUX_RT_MUTEX_H
13 #define __LINUX_RT_MUTEX_H
15 #include <linux/linkage.h>
16 #include <linux/plist.h>
17 #include <linux/spinlock_types.h>
20 * The rt_mutex structure
22 * @wait_lock: spinlock to protect the structure
23 * @wait_list: pilist head to enqueue waiters in priority order
24 * @owner: the mutex owner
28 struct plist_head wait_list
;
29 struct task_struct
*owner
;
30 #ifdef CONFIG_DEBUG_RT_MUTEXES
32 const char *name
, *file
;
38 struct rt_mutex_waiter
;
39 struct hrtimer_sleeper
;
41 #ifdef CONFIG_DEBUG_RT_MUTEXES
42 extern int rt_mutex_debug_check_no_locks_freed(const void *from
,
44 extern void rt_mutex_debug_check_no_locks_held(struct task_struct
*task
);
46 static inline int rt_mutex_debug_check_no_locks_freed(const void *from
,
51 # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
54 #ifdef CONFIG_DEBUG_RT_MUTEXES
55 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
56 , .name = #mutexname, .file = __FILE__, .line = __LINE__
57 # define rt_mutex_init(mutex) __rt_mutex_init(mutex, __FUNCTION__)
58 extern void rt_mutex_debug_task_free(struct task_struct
*tsk
);
60 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
61 # define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL)
62 # define rt_mutex_debug_task_free(t) do { } while (0)
65 #define __RT_MUTEX_INITIALIZER(mutexname) \
66 { .wait_lock = SPIN_LOCK_UNLOCKED \
67 , .wait_list = PLIST_HEAD_INIT(mutexname.wait_list, mutexname.wait_lock) \
69 __DEBUG_RT_MUTEX_INITIALIZER(mutexname)}
71 #define DEFINE_RT_MUTEX(mutexname) \
72 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
75 * rt_mutex_is_locked - is the mutex locked
76 * @lock: the mutex to be queried
78 * Returns 1 if the mutex is locked, 0 if unlocked.
80 static inline int rt_mutex_is_locked(struct rt_mutex
*lock
)
82 return lock
->owner
!= NULL
;
85 extern void __rt_mutex_init(struct rt_mutex
*lock
, const char *name
);
86 extern void rt_mutex_destroy(struct rt_mutex
*lock
);
88 extern void rt_mutex_lock(struct rt_mutex
*lock
);
89 extern int rt_mutex_lock_interruptible(struct rt_mutex
*lock
,
91 extern int rt_mutex_timed_lock(struct rt_mutex
*lock
,
92 struct hrtimer_sleeper
*timeout
,
95 extern int rt_mutex_trylock(struct rt_mutex
*lock
);
97 extern void rt_mutex_unlock(struct rt_mutex
*lock
);
99 #ifdef CONFIG_RT_MUTEXES
100 # define INIT_RT_MUTEXES(tsk) \
101 .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters, tsk.pi_lock), \
102 INIT_RT_MUTEX_DEBUG(tsk)
104 # define INIT_RT_MUTEXES(tsk)