Stephen Blackheath's GHC/ARM registerised port
[ghc.git] / rts / OldARMAtomic.c
1 #include "PosixSource.h"
2 #include "Stg.h"
3
4 #if defined(HAVE_SCHED_H)
5 #include <sched.h>
6 #endif
7
8 #if defined(THREADED_RTS)
9
10 #if arm_HOST_ARCH && defined(PRE_ARMv6)
11
12 static volatile int atomic_spin = 0;
13
14 static int arm_atomic_spin_trylock (void)
15 {
16 int result;
17
18 asm volatile (
19 "swp %0, %1, [%2]\n"
20 : "=&r,&r" (result)
21 : "r,0" (1), "r,r" (&atomic_spin)
22 : "memory");
23 if (result == 0)
24 return 0;
25 else
26 return -1;
27 }
28
29 void arm_atomic_spin_lock()
30 {
31 while (arm_atomic_spin_trylock())
32 #if defined(HAVE_SCHED_H)
33 sched_yield();
34 #else
35 ; // inefficient on non-POSIX.
36 #endif
37 }
38
39 void arm_atomic_spin_unlock()
40 {
41 atomic_spin = 0;
42 }
43
44 #endif /* arm_HOST_ARCH && defined(PRE_ARMv6) */
45
46 #endif /* defined(THREADED_RTS) */
47