MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / include / asm-nios2nommu / semaphore-helper.h
bloba8905d13656adc74093f629414fdac335e340470
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)
40 int ret;
41 unsigned long flags;
43 spin_lock_irqsave(&semaphore_wake_lock, flags);
44 ret = 0;
45 if (atomic_read(&sem->waking) > 0) {
46 atomic_dec(&sem->waking);
47 ret = 1;
49 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
50 return ret;
54 * waking_non_zero_interruptible:
55 * 1 got the lock
56 * 0 go to sleep
57 * -EINTR interrupted
59 static inline int waking_non_zero_interruptible(struct semaphore *sem,
60 struct task_struct *tsk)
62 int ret;
63 unsigned long flags;
65 spin_lock_irqsave(&semaphore_wake_lock, flags);
66 ret = 0;
67 if (atomic_read(&sem->waking) > 0) {
68 atomic_dec(&sem->waking);
69 ret = 1;
70 } else if (signal_pending(tsk)) {
71 atomic_inc(&sem->count);
72 ret = -EINTR;
74 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
75 return ret;
79 * waking_non_zero_trylock:
80 * 1 failed to lock
81 * 0 got the lock
83 static inline int waking_non_zero_trylock(struct semaphore *sem)
85 int ret;
86 unsigned long flags;
88 spin_lock_irqsave(&semaphore_wake_lock, flags);
89 ret = 1;
90 if (atomic_read(&sem->waking) > 0) {
91 atomic_dec(&sem->waking);
92 ret = 0;
93 } else
94 atomic_inc(&sem->count);
95 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
96 return ret;
99 #endif