aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-cris/semaphore-helper.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-cris/semaphore-helper.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-cris/semaphore-helper.h')
-rw-r--r--include/asm-cris/semaphore-helper.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/include/asm-cris/semaphore-helper.h b/include/asm-cris/semaphore-helper.h
new file mode 100644
index 000000000000..dbd0f30b85b6
--- /dev/null
+++ b/include/asm-cris/semaphore-helper.h
@@ -0,0 +1,81 @@
1/* $Id: semaphore-helper.h,v 1.3 2001/03/26 15:00:33 orjanf Exp $
2 *
3 * SMP- and interrupt-safe semaphores helper functions. Generic versions, no
4 * optimizations whatsoever...
5 *
6 */
7
8#ifndef _ASM_SEMAPHORE_HELPER_H
9#define _ASM_SEMAPHORE_HELPER_H
10
11#include <asm/atomic.h>
12#include <linux/errno.h>
13
14#define read(a) ((a)->counter)
15#define inc(a) (((a)->counter)++)
16#define dec(a) (((a)->counter)--)
17
18#define count_inc(a) ((*(a))++)
19
20/*
21 * These two _must_ execute atomically wrt each other.
22 */
23extern inline void wake_one_more(struct semaphore * sem)
24{
25 atomic_inc(&sem->waking);
26}
27
28extern inline int waking_non_zero(struct semaphore *sem)
29{
30 unsigned long flags;
31 int ret = 0;
32
33 local_save_flags(flags);
34 local_irq_disable();
35 if (read(&sem->waking) > 0) {
36 dec(&sem->waking);
37 ret = 1;
38 }
39 local_irq_restore(flags);
40 return ret;
41}
42
43extern inline int waking_non_zero_interruptible(struct semaphore *sem,
44 struct task_struct *tsk)
45{
46 int ret = 0;
47 unsigned long flags;
48
49 local_save_flags(flags);
50 local_irq_disable();
51 if (read(&sem->waking) > 0) {
52 dec(&sem->waking);
53 ret = 1;
54 } else if (signal_pending(tsk)) {
55 inc(&sem->count);
56 ret = -EINTR;
57 }
58 local_irq_restore(flags);
59 return ret;
60}
61
62extern inline int waking_non_zero_trylock(struct semaphore *sem)
63{
64 int ret = 1;
65 unsigned long flags;
66
67 local_save_flags(flags);
68 local_irq_disable();
69 if (read(&sem->waking) <= 0)
70 inc(&sem->count);
71 else {
72 dec(&sem->waking);
73 ret = 0;
74 }
75 local_irq_restore(flags);
76 return ret;
77}
78
79#endif /* _ASM_SEMAPHORE_HELPER_H */
80
81