volatile does not imply compiler fence on gcc, so this code has a race condition when updating read/write_position, you need compiler barriers here
>data[write_position] = value;
>COMPILER_BARRIER(); // __asm__ volatile("":::"memory");
>write_position = (write_position + 1U) % LENGTH;
and same in Skip()