[PATCH] i4l: remove unneeded include/linux/isdn/tpam.h
[linux-2.6/zen-sources.git] / include / linux / rtmutex.h
blobfa4a3b82ba704a9bc22144eeacdc22d345a60b6f
1 /*
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
26 struct rt_mutex {
27 spinlock_t wait_lock;
28 struct plist_head wait_list;
29 struct task_struct *owner;
30 #ifdef CONFIG_DEBUG_RT_MUTEXES
31 int save_state;
32 struct list_head held_list_entry;
33 unsigned long acquire_ip;
34 const char *name, *file;
35 int line;
36 void *magic;
37 #endif
40 struct rt_mutex_waiter;
41 struct hrtimer_sleeper;
43 #ifdef CONFIG_DEBUG_RT_MUTEXES
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)
51 return 0;
53 # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
54 #endif
56 #ifdef CONFIG_DEBUG_RT_MUTEXES
57 # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
58 , .name = #mutexname, .file = __FILE__, .line = __LINE__
59 # define rt_mutex_init(mutex) __rt_mutex_init(mutex, __FUNCTION__)
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)
64 # define rt_mutex_debug_task_free(t) do { } while (0)
65 #endif
67 #define __RT_MUTEX_INITIALIZER(mutexname) \
68 { .wait_lock = SPIN_LOCK_UNLOCKED \
69 , .wait_list = PLIST_HEAD_INIT(mutexname.wait_list, mutexname.wait_lock) \
70 , .owner = NULL \
71 __DEBUG_RT_MUTEX_INITIALIZER(mutexname)}
73 #define DEFINE_RT_MUTEX(mutexname) \
74 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
76 /***
77 * rt_mutex_is_locked - is the mutex locked
78 * @lock: the mutex to be queried
80 * Returns 1 if the mutex is locked, 0 if unlocked.
82 static inline int rt_mutex_is_locked(struct rt_mutex *lock)
84 return lock->owner != NULL;
87 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
88 extern void rt_mutex_destroy(struct rt_mutex *lock);
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);
97 extern int rt_mutex_trylock(struct rt_mutex *lock);
99 extern void rt_mutex_unlock(struct rt_mutex *lock);
101 #ifdef CONFIG_DEBUG_RT_MUTEXES
102 # define INIT_RT_MUTEX_DEBUG(tsk) \
103 .held_list_head = LIST_HEAD_INIT(tsk.held_list_head), \
104 .held_list_lock = SPIN_LOCK_UNLOCKED
105 #else
106 # define INIT_RT_MUTEX_DEBUG(tsk)
107 #endif
109 #ifdef CONFIG_RT_MUTEXES
110 # define INIT_RT_MUTEXES(tsk) \
111 .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters, tsk.pi_lock), \
112 INIT_RT_MUTEX_DEBUG(tsk)
113 #else
114 # define INIT_RT_MUTEXES(tsk)
115 #endif
117 #endif