1 #ifndef _NIOS2NOMMU_SEMAPHORE_HELPER_H
2 #define _NIOS2NOMMU_SEMAPHORE_HELPER_H
4 /*--------------------------------------------------------------------
6 * include/asm-nios2nommu/semaphore.h
8 * SMP- and interrupt-safe semaphores helper functions.
10 * Derived from M68knommu
12 * (C) Copyright 1996 Linus Torvalds
13 * m68k version by Andreas Schwab
14 * Copyright (C) 2004 Microtronix Datacom Ltd
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * Jan/20/2004 dgt NiosII
28 ---------------------------------------------------------------------*/
31 * These two _must_ execute atomically wrt each other.
33 static inline void wake_one_more(struct semaphore
* sem
)
35 atomic_inc(&sem
->waking
);
38 static inline int waking_non_zero(struct semaphore
*sem
)
43 spin_lock_irqsave(&semaphore_wake_lock
, flags
);
45 if (atomic_read(&sem
->waking
) > 0) {
46 atomic_dec(&sem
->waking
);
49 spin_unlock_irqrestore(&semaphore_wake_lock
, flags
);
54 * waking_non_zero_interruptible:
59 static inline int waking_non_zero_interruptible(struct semaphore
*sem
,
60 struct task_struct
*tsk
)
65 spin_lock_irqsave(&semaphore_wake_lock
, flags
);
67 if (atomic_read(&sem
->waking
) > 0) {
68 atomic_dec(&sem
->waking
);
70 } else if (signal_pending(tsk
)) {
71 atomic_inc(&sem
->count
);
74 spin_unlock_irqrestore(&semaphore_wake_lock
, flags
);
79 * waking_non_zero_trylock:
83 static inline int waking_non_zero_trylock(struct semaphore
*sem
)
88 spin_lock_irqsave(&semaphore_wake_lock
, flags
);
90 if (atomic_read(&sem
->waking
) > 0) {
91 atomic_dec(&sem
->waking
);
94 atomic_inc(&sem
->count
);
95 spin_unlock_irqrestore(&semaphore_wake_lock
, flags
);