diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-h8300/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-h8300/semaphore-helper.h')
-rw-r--r-- | include/asm-h8300/semaphore-helper.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/include/asm-h8300/semaphore-helper.h b/include/asm-h8300/semaphore-helper.h new file mode 100644 index 000000000000..29e0fbf1acb7 --- /dev/null +++ b/include/asm-h8300/semaphore-helper.h | |||
@@ -0,0 +1,86 @@ | |||
1 | #ifndef _H8300_SEMAPHORE_HELPER_H | ||
2 | #define _H8300_SEMAPHORE_HELPER_H | ||
3 | |||
4 | /* | ||
5 | * SMP- and interrupt-safe semaphores helper functions. | ||
6 | * | ||
7 | * (C) Copyright 1996 Linus Torvalds | ||
8 | * | ||
9 | * based on | ||
10 | * m68k version by Andreas Schwab | ||
11 | */ | ||
12 | |||
13 | #include <linux/config.h> | ||
14 | #include <linux/errno.h> | ||
15 | |||
16 | /* | ||
17 | * These two _must_ execute atomically wrt each other. | ||
18 | */ | ||
19 | static inline void wake_one_more(struct semaphore * sem) | ||
20 | { | ||
21 | atomic_inc((atomic_t *)&sem->sleepers); | ||
22 | } | ||
23 | |||
24 | static inline int waking_non_zero(struct semaphore *sem) | ||
25 | { | ||
26 | int ret; | ||
27 | unsigned long flags; | ||
28 | |||
29 | spin_lock_irqsave(&semaphore_wake_lock, flags); | ||
30 | ret = 0; | ||
31 | if (sem->sleepers > 0) { | ||
32 | sem->sleepers--; | ||
33 | ret = 1; | ||
34 | } | ||
35 | spin_unlock_irqrestore(&semaphore_wake_lock, flags); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | /* | ||
40 | * waking_non_zero_interruptible: | ||
41 | * 1 got the lock | ||
42 | * 0 go to sleep | ||
43 | * -EINTR interrupted | ||
44 | */ | ||
45 | static inline int waking_non_zero_interruptible(struct semaphore *sem, | ||
46 | struct task_struct *tsk) | ||
47 | { | ||
48 | int ret; | ||
49 | unsigned long flags; | ||
50 | |||
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; | ||
59 | } | ||
60 | spin_unlock_irqrestore(&semaphore_wake_lock, flags); | ||
61 | return ret; | ||
62 | } | ||
63 | |||
64 | /* | ||
65 | * waking_non_zero_trylock: | ||
66 | * 1 failed to lock | ||
67 | * 0 got the lock | ||
68 | */ | ||
69 | static inline int waking_non_zero_trylock(struct semaphore *sem) | ||
70 | { | ||
71 | int ret; | ||
72 | unsigned long flags; | ||
73 | |||
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; | ||
81 | } | ||
82 | spin_unlock_irqrestore(&semaphore_wake_lock, flags); | ||
83 | return ret; | ||
84 | } | ||
85 | |||
86 | #endif | ||