> The mix of global buffer and passed-in struct defining the buffer made me sad. So did the lack of atomic increments and decrements (volatile ain't sufficient). Don't get me started on the getchar routine.
It's for MSP430, and seems to be oriented in single core embedded microcontrollers. Those things have no atomic operations, other than disabling interrupts.
You'd be right for multicore chips or if data type is larger than word size or if data is not aligned.
But in this case, this code is correct for this architecture. All of those things you mentioned are perfectly normal and acceptable when programming microcontrollers.
I guess you're assuming the compiler will issue an "increment" instruction for the ++, and that instruction is atomic.
It's not a great coding practice. Move to a different processor (this happens!) and your code turns into a load-add-store, gets interrupted halfway through, and you scratch your head for a while about the mysterious and flaky FIFO failures.
Been there. At least a gesture towards an atomic operation would be nice, when you have data shared between interrupt and non-interrupt code.
It's for MSP430, and seems to be oriented in single core embedded microcontrollers. Those things have no atomic operations, other than disabling interrupts.
You'd be right for multicore chips or if data type is larger than word size or if data is not aligned.
But in this case, this code is correct for this architecture. All of those things you mentioned are perfectly normal and acceptable when programming microcontrollers.
http://www.simplyembedded.org/tutorials/msp430-architecture/
http://en.wikipedia.org/wiki/TI_MSP430