Async syscall helper
[akaros.git] / user / parlib / riscv / atomic.c
1 #include <ros/atomic.h>
2 #include <stdint.h>
3 #include <spinlock.h>
4
5 static spinlock_t lock = SPINLOCK_INITIALIZER;
6
7 #define bool_cas_func(size, type) \
8   bool __sync_bool_compare_and_swap_ ## size(type* ptr, type oldval, type newval) \
9   { \
10         bool success = false; \
11         spinlock_lock(&lock); \
12         if (*ptr == oldval) \
13         { \
14           *ptr = newval; \
15           success = true; \
16         } \
17         spinlock_unlock(&lock); \
18         return success; \
19   }
20
21 bool_cas_func(1, uint8_t)
22 bool_cas_func(2, uint16_t)
23 bool_cas_func(4, uint32_t)
24 bool_cas_func(8, uint64_t)