1 #ifndef _M68K_SEMAPHORE_HELPER_H
2 #define _M68K_SEMAPHORE_HELPER_H
5 * SMP- and interrupt-safe semaphores helper functions.
7 * (C) Copyright 1996 Linus Torvalds
9 * m68k version by Andreas Schwab
12 #include <linux/config.h>
13 #include <linux/errno.h>
16 * These two _must_ execute atomically wrt each other.
18 static inline void wake_one_more(struct semaphore
* sem
)
20 atomic_inc(&sem
->waking
);
23 #ifndef CONFIG_RMW_INSNS
24 extern spinlock_t semaphore_wake_lock
;
27 static inline int waking_non_zero(struct semaphore
*sem
)
30 #ifndef CONFIG_RMW_INSNS
33 spin_lock_irqsave(&semaphore_wake_lock
, flags
);
35 if (atomic_read(&sem
->waking
) > 0) {
36 atomic_dec(&sem
->waking
);
39 spin_unlock_irqrestore(&semaphore_wake_lock
, flags
);
51 : "=d" (ret
), "=d" (tmp1
), "=d" (tmp2
)
52 : "m" (sem
->waking
), "0" (0), "1" (sem
->waking
));
59 * waking_non_zero_interruptible:
64 static inline int waking_non_zero_interruptible(struct semaphore
*sem
,
65 struct task_struct
*tsk
)
68 #ifndef CONFIG_RMW_INSNS
71 spin_lock_irqsave(&semaphore_wake_lock
, flags
);
73 if (atomic_read(&sem
->waking
) > 0) {
74 atomic_dec(&sem
->waking
);
76 } else if (signal_pending(tsk
)) {
77 atomic_inc(&sem
->count
);
80 spin_unlock_irqrestore(&semaphore_wake_lock
, flags
);
93 : "=d" (ret
), "=d" (tmp1
), "=d" (tmp2
)
94 : "m" (sem
->waking
), "i" (&&next
), "0" (0), "1" (sem
->waking
));
95 if (signal_pending(tsk
)) {
96 atomic_inc(&sem
->count
);
106 * waking_non_zero_trylock:
110 static inline int waking_non_zero_trylock(struct semaphore
*sem
)
113 #ifndef CONFIG_RMW_INSNS
116 spin_lock_irqsave(&semaphore_wake_lock
, flags
);
118 if (atomic_read(&sem
->waking
) > 0) {
119 atomic_dec(&sem
->waking
);
122 atomic_inc(&sem
->count
);
123 spin_unlock_irqrestore(&semaphore_wake_lock
, flags
);
135 : "=d" (ret
), "=d" (tmp1
), "=d" (tmp2
)
136 : "m" (sem
->waking
), "0" (1), "1" (sem
->waking
));
138 atomic_inc(&sem
->count
);