-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcas.cpp
More file actions
41 lines (31 loc) · 868 Bytes
/
cas.cpp
File metadata and controls
41 lines (31 loc) · 868 Bytes
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
30
31
32
33
34
35
36
37
38
39
40
41
#include "cas.h"
bool __atomic_compare_exchange_1(volatile bool *mem, bool *expected,
bool desired, bool weak, int success,
int failure) {
bool status = true;
// noInterrupts();
if (*mem == *expected)
*mem = desired;
else
status = false;
// interrupts();
return status;
}
static inline unsigned long arch_local_irq_save(void) {
unsigned long flags;
asm volatile("rsil %0, 1" : "=a"(flags)::"memory");
return flags;
}
static inline void arch_local_irq_restore(unsigned long flags) {
asm volatile("wsr %0, ps; rsync" ::"a"(flags) : "memory");
}
bool cas(volatile uint8_t *mem, uint8_t expected, uint8_t desired) {
bool status = true;
// noInterrupts();
if (*mem == expected)
*mem = desired;
else
status = false;
// interrupts();
return status;
}