aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-xtensa/semaphore.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-xtensa/semaphore.h')
-rw-r--r--include/asm-xtensa/semaphore.h49
1 files changed, 11 insertions, 38 deletions
diff --git a/include/asm-xtensa/semaphore.h b/include/asm-xtensa/semaphore.h
index db740b8bc6f0..09e89ab3eb61 100644
--- a/include/asm-xtensa/semaphore.h
+++ b/include/asm-xtensa/semaphore.h
@@ -20,28 +20,19 @@ struct semaphore {
20 atomic_t count; 20 atomic_t count;
21 int sleepers; 21 int sleepers;
22 wait_queue_head_t wait; 22 wait_queue_head_t wait;
23#if WAITQUEUE_DEBUG
24 long __magic;
25#endif
26}; 23};
27 24
28#if WAITQUEUE_DEBUG 25#define __SEMAPHORE_INITIALIZER(name,n) \
29# define __SEM_DEBUG_INIT(name) \ 26{ \
30 , (int)&(name).__magic 27 .count = ATOMIC_INIT(n), \
31#else 28 .sleepers = 0, \
32# define __SEM_DEBUG_INIT(name) 29 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
33#endif 30}
34
35#define __SEMAPHORE_INITIALIZER(name,count) \
36 { ATOMIC_INIT(count), \
37 0, \
38 __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
39 __SEM_DEBUG_INIT(name) }
40 31
41#define __MUTEX_INITIALIZER(name) \ 32#define __MUTEX_INITIALIZER(name) \
42 __SEMAPHORE_INITIALIZER(name, 1) 33 __SEMAPHORE_INITIALIZER(name, 1)
43 34
44#define __DECLARE_SEMAPHORE_GENERIC(name,count) \ 35#define __DECLARE_SEMAPHORE_GENERIC(name,count) \
45 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count) 36 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
46 37
47#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1) 38#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
@@ -49,17 +40,8 @@ struct semaphore {
49 40
50static inline void sema_init (struct semaphore *sem, int val) 41static inline void sema_init (struct semaphore *sem, int val)
51{ 42{
52/*
53 * *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val);
54 *
55 * i'd rather use the more flexible initialization above, but sadly
56 * GCC 2.7.2.3 emits a bogus warning. EGCS doesnt. Oh well.
57 */
58 atomic_set(&sem->count, val); 43 atomic_set(&sem->count, val);
59 init_waitqueue_head(&sem->wait); 44 init_waitqueue_head(&sem->wait);
60#if WAITQUEUE_DEBUG
61 sem->__magic = (int)&sem->__magic;
62#endif
63} 45}
64 46
65static inline void init_MUTEX (struct semaphore *sem) 47static inline void init_MUTEX (struct semaphore *sem)
@@ -81,9 +63,7 @@ extern spinlock_t semaphore_wake_lock;
81 63
82static inline void down(struct semaphore * sem) 64static inline void down(struct semaphore * sem)
83{ 65{
84#if WAITQUEUE_DEBUG 66 might_sleep();
85 CHECK_MAGIC(sem->__magic);
86#endif
87 67
88 if (atomic_sub_return(1, &sem->count) < 0) 68 if (atomic_sub_return(1, &sem->count) < 0)
89 __down(sem); 69 __down(sem);
@@ -92,9 +72,8 @@ static inline void down(struct semaphore * sem)
92static inline int down_interruptible(struct semaphore * sem) 72static inline int down_interruptible(struct semaphore * sem)
93{ 73{
94 int ret = 0; 74 int ret = 0;
95#if WAITQUEUE_DEBUG 75
96 CHECK_MAGIC(sem->__magic); 76 might_sleep();
97#endif
98 77
99 if (atomic_sub_return(1, &sem->count) < 0) 78 if (atomic_sub_return(1, &sem->count) < 0)
100 ret = __down_interruptible(sem); 79 ret = __down_interruptible(sem);
@@ -104,9 +83,6 @@ static inline int down_interruptible(struct semaphore * sem)
104static inline int down_trylock(struct semaphore * sem) 83static inline int down_trylock(struct semaphore * sem)
105{ 84{
106 int ret = 0; 85 int ret = 0;
107#if WAITQUEUE_DEBUG
108 CHECK_MAGIC(sem->__magic);
109#endif
110 86
111 if (atomic_sub_return(1, &sem->count) < 0) 87 if (atomic_sub_return(1, &sem->count) < 0)
112 ret = __down_trylock(sem); 88 ret = __down_trylock(sem);
@@ -119,9 +95,6 @@ static inline int down_trylock(struct semaphore * sem)
119 */ 95 */
120static inline void up(struct semaphore * sem) 96static inline void up(struct semaphore * sem)
121{ 97{
122#if WAITQUEUE_DEBUG
123 CHECK_MAGIC(sem->__magic);
124#endif
125 if (atomic_add_return(1, &sem->count) <= 0) 98 if (atomic_add_return(1, &sem->count) <= 0)
126 __up(sem); 99 __up(sem);
127} 100}