ia64/xen-unstable

view extras/mini-os/include/x86/arch_spinlock.h @ 16838:945820bfedb6

minios: POSIX fixes
Fixes some functions which are POSIX. Also make them ifndef HAVE_LIBC.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jan 22 14:20:22 2008 +0000 (2008-01-22)
parents b631e7885b5f
children a905c582a406
line source
3 #ifndef __ARCH_ASM_SPINLOCK_H
4 #define __ARCH_ASM_SPINLOCK_H
6 #include <lib.h>
9 #define ARCH_SPIN_LOCK_UNLOCKED (spinlock_t) { 1 }
11 /*
12 * Simple spin lock operations. There are two variants, one clears IRQ's
13 * on the local processor, one does not.
14 *
15 * We make no fairness assumptions. They have a cost.
16 */
18 #define arch_spin_is_locked(x) (*(volatile signed char *)(&(x)->slock) <= 0)
19 #define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x))
21 #define spin_lock_string \
22 "1:\n" \
23 LOCK \
24 "decb %0\n\t" \
25 "jns 3f\n" \
26 "2:\t" \
27 "rep;nop\n\t" \
28 "cmpb $0,%0\n\t" \
29 "jle 2b\n\t" \
30 "jmp 1b\n" \
31 "3:\n\t"
33 #define spin_lock_string_flags \
34 "1:\n" \
35 LOCK \
36 "decb %0\n\t" \
37 "jns 4f\n\t" \
38 "2:\t" \
39 "testl $0x200, %1\n\t" \
40 "jz 3f\n\t" \
41 "#sti\n\t" \
42 "3:\t" \
43 "rep;nop\n\t" \
44 "cmpb $0, %0\n\t" \
45 "jle 3b\n\t" \
46 "#cli\n\t" \
47 "jmp 1b\n" \
48 "4:\n\t"
50 /*
51 * This works. Despite all the confusion.
52 * (except on PPro SMP or if we are using OOSTORE)
53 * (PPro errata 66, 92)
54 */
56 #define spin_unlock_string \
57 "xchgb %b0, %1" \
58 :"=q" (oldval), "=m" (lock->slock) \
59 :"0" (oldval) : "memory"
61 static inline void _raw_spin_unlock(spinlock_t *lock)
62 {
63 char oldval = 1;
64 __asm__ __volatile__(
65 spin_unlock_string
66 );
67 }
69 static inline int _raw_spin_trylock(spinlock_t *lock)
70 {
71 char oldval;
72 __asm__ __volatile__(
73 "xchgb %b0,%1\n"
74 :"=q" (oldval), "=m" (lock->slock)
75 :"0" (0) : "memory");
76 return oldval > 0;
77 }
79 static inline void _raw_spin_lock(spinlock_t *lock)
80 {
81 __asm__ __volatile__(
82 spin_lock_string
83 :"=m" (lock->slock) : : "memory");
84 }
86 static inline void _raw_spin_lock_flags (spinlock_t *lock, unsigned long flags)
87 {
88 __asm__ __volatile__(
89 spin_lock_string_flags
90 :"=m" (lock->slock) : "r" (flags) : "memory");
91 }
93 #endif