[NETFILTER]: PPTP conntrack: clean up debugging cruft
[hh.org.git] / include / asm-h8300 / semaphore-helper.h
blob4fea36be5fd85df5004a23af32e678db21868835
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/errno.h>
16 * These two _must_ execute atomically wrt each other.
18 static inline void wake_one_more(struct semaphore * sem)
20 atomic_inc((atomic_t *)&sem->sleepers);
23 static inline int waking_non_zero(struct semaphore *sem)
25 int ret;
26 unsigned long flags;
28 spin_lock_irqsave(&semaphore_wake_lock, flags);
29 ret = 0;
30 if (sem->sleepers > 0) {
31 sem->sleepers--;
32 ret = 1;
34 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
35 return ret;
39 * waking_non_zero_interruptible:
40 * 1 got the lock
41 * 0 go to sleep
42 * -EINTR interrupted
44 static inline int waking_non_zero_interruptible(struct semaphore *sem,
45 struct task_struct *tsk)
47 int ret;
48 unsigned long flags;
50 spin_lock_irqsave(&semaphore_wake_lock, flags);
51 ret = 0;
52 if (sem->sleepers > 0) {
53 sem->sleepers--;
54 ret = 1;
55 } else if (signal_pending(tsk)) {
56 atomic_inc(&sem->count);
57 ret = -EINTR;
59 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
60 return ret;
64 * waking_non_zero_trylock:
65 * 1 failed to lock
66 * 0 got the lock
68 static inline int waking_non_zero_trylock(struct semaphore *sem)
70 int ret;
71 unsigned long flags;
73 spin_lock_irqsave(&semaphore_wake_lock, flags);
74 ret = 1;
75 if (sem->sleepers <= 0)
76 atomic_inc(&sem->count);
77 else {
78 sem->sleepers--;
79 ret = 0;
81 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
82 return ret;
85 #endif