From: Mikko Rasa Date: Sat, 9 Nov 2013 22:30:36 +0000 (+0200) Subject: Avoid a race condition with the last bytes of an S88 read X-Git-Url: http://git.tdb.fi/?p=model-railway-devices.git;a=commitdiff_plain;h=f0f49dd7ecb27635906557267a733dd8bdb8a9f7 Avoid a race condition with the last bytes of an S88 read --- diff --git a/arducontrol/s88.c b/arducontrol/s88.c index 142455a..bd53deb 100644 --- a/arducontrol/s88.c +++ b/arducontrol/s88.c @@ -28,8 +28,11 @@ void s88_init(void) void s88_check(void) { + /* Check remaining read count before ringbuffer fill. If it is zero, no + more bytes are arriving in the buffer and the contents can be sent out. */ + uint8_t rc = s88_read_count; uint8_t count = ringbuffer_fill(s88_buffer); - if(count>=4 || (count>0 && !s88_read_count)) + if(count>=4 || (count>0 && !rc)) { uint8_t reply[10];