Introduce ATOMIC_START and ATOMIC_END.
As a sample application, use it in queue_empty(). There's also ATOMIC_BLOCK() coming with avr-libc, but this requires a C99 compiler while Arduino IDE insists on running avr-gcc in C89 mode.
This commit is contained in:
parent
569adeecd1
commit
69da7c5b15
11
dda_queue.c
11
dda_queue.c
|
|
@ -47,14 +47,11 @@ uint8_t queue_full() {
|
|||
|
||||
/// check if the queue is completely empty
|
||||
uint8_t queue_empty() {
|
||||
uint8_t save_reg = SREG;
|
||||
cli();
|
||||
CLI_SEI_BUG_MEMORY_BARRIER();
|
||||
|
||||
uint8_t result = ((mb_tail == mb_head) && (movebuffer[mb_tail].live == 0))?255:0;
|
||||
uint8_t result;
|
||||
|
||||
MEMORY_BARRIER();
|
||||
SREG = save_reg;
|
||||
ATOMIC_START
|
||||
result = ((mb_tail == mb_head) && (movebuffer[mb_tail].live == 0))?255:0;
|
||||
ATOMIC_END
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,4 +28,13 @@
|
|||
#define CLI_SEI_BUG_MEMORY_BARRIER()
|
||||
#endif
|
||||
|
||||
#define ATOMIC_START { \
|
||||
uint8_t save_reg = SREG; \
|
||||
cli(); \
|
||||
CLI_SEI_BUG_MEMORY_BARRIER();
|
||||
|
||||
#define ATOMIC_END MEMORY_BARRIER(); \
|
||||
SREG = save_reg; \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue