summaryrefslogtreecommitdiff
path: root/software/smp/atomic.h
blob: 074c6a2c7fd4f8a8f5784607b3793b3642375cda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef SIFIVE_ATOMIC_H
#define SIFIVE_ATOMIC_H

#define ATOMIC_INIT(x)		\
	{			\
		.counter = (x),	\
	}

typedef struct {
  int counter;
} atomic_t;

static inline int atomic_xchg(atomic_t *v, int n)
{
  register int c;

  __asm__ __volatile__ (
    "amoswap.w.aqrl %0, %2, %1"
    : "=r" (c), "+A" (v->counter)
    : "r" (n));
  return c;
}

static inline void mb(void)
{
  __asm__ __volatile__ ("fence");
}

#endif