]> git.tdb.fi Git - model-railway-devices.git/commitdiff
Avoid a race condition with the last bytes of an S88 read
authorMikko Rasa <tdb@tdb.fi>
Sat, 9 Nov 2013 22:30:36 +0000 (00:30 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 9 Nov 2013 22:30:36 +0000 (00:30 +0200)
arducontrol/s88.c

index 142455a13ae551e1cb724e1a6b976e231d35e1ba..bd53deb72f55e252e2c88db1ed609e42fa896bae 100644 (file)
@@ -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];