direct-io.hg

view extras/mini-os/include/spinlock.h @ 10690:77fe42f6442b

[IA64] Fix the ia64 build.
Signed-off-by: Alex Williamson <alex.williamson@hp.com>
author kfraser@localhost.localdomain
date Fri Jul 14 10:49:05 2006 +0100 (2006-07-14)
parents 7557f0b4098c
children
line source
1 #ifndef __ASM_SPINLOCK_H
2 #define __ASM_SPINLOCK_H
4 #include <lib.h>
6 /*
7 * Your basic SMP spinlocks, allowing only a single CPU anywhere
8 */
10 typedef struct {
11 volatile unsigned int slock;
12 } spinlock_t;
14 #define SPINLOCK_MAGIC 0xdead4ead
16 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 1 }
18 #define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0)
20 /*
21 * Simple spin lock operations. There are two variants, one clears IRQ's
22 * on the local processor, one does not.
23 *
24 * We make no fairness assumptions. They have a cost.
25 */
27 #define spin_is_locked(x) (*(volatile signed char *)(&(x)->slock) <= 0)
28 #define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x))
30 #define spin_lock_string \
31 "1:\n" \
32 LOCK \
33 "decb %0\n\t" \
34 "jns 3f\n" \
35 "2:\t" \
36 "rep;nop\n\t" \
37 "cmpb $0,%0\n\t" \
38 "jle 2b\n\t" \
39 "jmp 1b\n" \
40 "3:\n\t"
42 #define spin_lock_string_flags \
43 "1:\n" \
44 LOCK \
45 "decb %0\n\t" \
46 "jns 4f\n\t" \
47 "2:\t" \
48 "testl $0x200, %1\n\t" \
49 "jz 3f\n\t" \
50 "#sti\n\t" \
51 "3:\t" \
52 "rep;nop\n\t" \
53 "cmpb $0, %0\n\t" \
54 "jle 3b\n\t" \
55 "#cli\n\t" \
56 "jmp 1b\n" \
57 "4:\n\t"
59 /*
60 * This works. Despite all the confusion.
61 * (except on PPro SMP or if we are using OOSTORE)
62 * (PPro errata 66, 92)
63 */
65 #define spin_unlock_string \
66 "xchgb %b0, %1" \
67 :"=q" (oldval), "=m" (lock->slock) \
68 :"0" (oldval) : "memory"
70 static inline void _raw_spin_unlock(spinlock_t *lock)
71 {
72 char oldval = 1;
73 __asm__ __volatile__(
74 spin_unlock_string
75 );
76 }
78 static inline int _raw_spin_trylock(spinlock_t *lock)
79 {
80 char oldval;
81 __asm__ __volatile__(
82 "xchgb %b0,%1\n"
83 :"=q" (oldval), "=m" (lock->slock)
84 :"0" (0) : "memory");
85 return oldval > 0;
86 }
88 static inline void _raw_spin_lock(spinlock_t *lock)
89 {
90 __asm__ __volatile__(
91 spin_lock_string
92 :"=m" (lock->slock) : : "memory");
93 }
95 static inline void _raw_spin_lock_flags (spinlock_t *lock, unsigned long flags)
96 {
97 __asm__ __volatile__(
98 spin_lock_string_flags
99 :"=m" (lock->slock) : "r" (flags) : "memory");
100 }
102 #define _spin_trylock(lock) ({_raw_spin_trylock(lock) ? \
103 1 : ({ 0;});})
105 #define _spin_lock(lock) \
106 do { \
107 _raw_spin_lock(lock); \
108 } while(0)
110 #define _spin_unlock(lock) \
111 do { \
112 _raw_spin_unlock(lock); \
113 } while (0)
116 #define spin_lock(lock) _spin_lock(lock)
117 #define spin_unlock(lock) _spin_unlock(lock)
119 #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
121 #endif