ad0aaf0a284acaad9855796743497de0f3082bf2
2 * arch/ubicom32/include/asm/semaphore-helper.h
3 * Semaphore related definitions for Ubicom32 architecture.
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
23 * Ubicom32 implementation derived from (with many thanks):
28 #ifndef _ASM_UBICOM32_SEMAPHORE_HELPER_H
29 #define _ASM_UBICOM32_SEMAPHORE_HELPER_H
32 * SMP- and interrupt-safe semaphores helper functions.
34 * (C) Copyright 1996 Linus Torvalds
36 * m68k version by Andreas Schwab
41 * These two _must_ execute atomically wrt each other.
43 static inline void wake_one_more(struct semaphore
* sem
)
45 atomic_inc(&sem
->waking
);
48 static inline int waking_non_zero(struct semaphore
*sem
)
53 spin_lock_irqsave(&semaphore_wake_lock
, flags
);
55 if (atomic_read(&sem
->waking
) > 0) {
56 atomic_dec(&sem
->waking
);
59 spin_unlock_irqrestore(&semaphore_wake_lock
, flags
);
64 * waking_non_zero_interruptible:
69 static inline int waking_non_zero_interruptible(struct semaphore
*sem
,
70 struct task_struct
*tsk
)
75 spin_lock_irqsave(&semaphore_wake_lock
, flags
);
77 if (atomic_read(&sem
->waking
) > 0) {
78 atomic_dec(&sem
->waking
);
80 } else if (signal_pending(tsk
)) {
81 atomic_inc(&sem
->count
);
84 spin_unlock_irqrestore(&semaphore_wake_lock
, flags
);
89 * waking_non_zero_trylock:
93 static inline int waking_non_zero_trylock(struct semaphore
*sem
)
98 spin_lock_irqsave(&semaphore_wake_lock
, flags
);
100 if (atomic_read(&sem
->waking
) > 0) {
101 atomic_dec(&sem
->waking
);
104 atomic_inc(&sem
->count
);
105 spin_unlock_irqrestore(&semaphore_wake_lock
, flags
);
109 #endif /* _ASM_UBICOM32_SEMAPHORE_HELPER_H */