[PATCH] bcm43xx: Fix array overrun in bcm43xx_geo_init
[linux-2.6/kmemtrace.git] / include / asm-h8300 / semaphore-helper.h
blob29e0fbf1acb70a7f75c4d8dee3058ef2f99abfba
1 #ifndef _H8300_SEMAPHORE_HELPER_H
2 #define _H8300_SEMAPHORE_HELPER_H
4 /*
5 * SMP- and interrupt-safe semaphores helper functions.
7 * (C) Copyright 1996 Linus Torvalds
9 * based on
10 * m68k version by Andreas Schwab
13 #include <linux/config.h>
14 #include <linux/errno.h>
17 * These two _must_ execute atomically wrt each other.
19 static inline void wake_one_more(struct semaphore * sem)
21 atomic_inc((atomic_t *)&sem->sleepers);
24 static inline int waking_non_zero(struct semaphore *sem)
26 int ret;
27 unsigned long flags;
29 spin_lock_irqsave(&semaphore_wake_lock, flags);
30 ret = 0;
31 if (sem->sleepers > 0) {
32 sem->sleepers--;
33 ret = 1;
35 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
36 return ret;
40 * waking_non_zero_interruptible:
41 * 1 got the lock
42 * 0 go to sleep
43 * -EINTR interrupted
45 static inline int waking_non_zero_interruptible(struct semaphore *sem,
46 struct task_struct *tsk)
48 int ret;
49 unsigned long flags;
51 spin_lock_irqsave(&semaphore_wake_lock, flags);
52 ret = 0;
53 if (sem->sleepers > 0) {
54 sem->sleepers--;
55 ret = 1;
56 } else if (signal_pending(tsk)) {
57 atomic_inc(&sem->count);
58 ret = -EINTR;
60 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
61 return ret;
65 * waking_non_zero_trylock:
66 * 1 failed to lock
67 * 0 got the lock
69 static inline int waking_non_zero_trylock(struct semaphore *sem)
71 int ret;
72 unsigned long flags;
74 spin_lock_irqsave(&semaphore_wake_lock, flags);
75 ret = 1;
76 if (sem->sleepers <= 0)
77 atomic_inc(&sem->count);
78 else {
79 sem->sleepers--;
80 ret = 0;
82 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
83 return ret;
86 #endif