On 2025-12-26 13:44, Gregory Nutt wrote:
And from what I gather, int16_t accesses are not atomic. Most 8-bit
CPUs
offer some hardware support for atomicity (AVR has shadow registers).
To my knowledge - and unless we're talking about different AVR families
- the shadow registers are not relevant here, those are only available
for access to 16 bit I/O registers (for example current count in 16 bit
timer/counter.)
For generic memory access, the only option to make the access to
multibyte values atomic is disabling interrupts.
This is not really a NuttX-specific problem, but would effect all
real-time
systems that use and ANSI C. I suppose you could define type int to be
type int-atomic and then exploit this hardware support in a
cpu-specific
way.
In the serial driver, the chosen solution was to simply reduce maximum
buffer size to fit uint8_t because branching the code with #ifdefs to
only disable interrupts if needed would make readability worse and the
only way I know to make a MAKE_THIS_BLOCK_ATOMIC_IF_NEEDED {} macro is
IIRC invalid with C89. Not sure if this solution will be applicable for
circbuf_s though because that is used throughout the source tree and at
least pipe driver allows buffers up to 64kB size.