1 |
/* PEAK Library |
2 |
* peak/arch/sparc/atomic.h. Generated from atomic.h.in by configure. |
3 |
* |
4 |
* Sun sparc32 atomic operations |
5 |
* |
6 |
* $Id: atomic.h.in,v 1.1 2007/05/24 12:54:10 mbuna Exp $ |
7 |
*/ |
8 |
#ifndef INCLUDED_PEAK_ATOMIC_H_ |
9 |
#define INCLUDED_PEAK_ATOMIC_H_ |
10 |
|
11 |
#ifdef HAVE_CONFIG_H |
12 |
#include "config.h" |
13 |
#endif |
14 |
|
15 |
typedef struct { volatile int counter; } peak_atomic_t; |
16 |
|
17 |
#define PEAK_ATOMIC_INIT(i) { (i) } |
18 |
|
19 |
#define peak_atomic_read(v) ((v)->counter) |
20 |
#define peak_atomic_set(v,i) (((v)->counter) = (i)) |
21 |
|
22 |
static void |
23 |
__attribute__ ((unused)) |
24 |
peak_atomic_add(int a, peak_atomic_t *v) |
25 |
{ |
26 |
static unsigned char lock; |
27 |
int tmp; |
28 |
|
29 |
__asm__ __volatile__("1: ldstub [%1], %0\n\t" |
30 |
" cmp %0, 0\n\t" |
31 |
" bne 1b\n\t" |
32 |
" nop" |
33 |
: "=&r" (tmp) |
34 |
: "r" (&lock) |
35 |
: "memory"); |
36 |
v->counter += a; |
37 |
__asm__ __volatile__("stb %%g0, [%0]" |
38 |
: /* no outputs */ |
39 |
: "r" (&lock) |
40 |
: "memory"); |
41 |
} |
42 |
|
43 |
#define peak_atomic_sub(a, v) peak_atomic_add(-a, v) |
44 |
#define peak_atomic_inc(v) peak_atomic_add(1, v) |
45 |
#define peak_atomic_dec(v) peak_atomic_add(-1, v) |
46 |
|
47 |
#endif /* INCLUDED_PEAK_ATOMIC_H_ */ |