]> granicus.if.org Git - esp-idf/commitdiff
bugfix(ringbuffer): Fix ringbuffer_send timeout bug
authorkooho <2229179028@qq.com>
Wed, 17 Jan 2018 05:28:41 +0000 (13:28 +0800)
committerkooho <2229179028@qq.com>
Mon, 22 Jan 2018 06:17:58 +0000 (14:17 +0800)
components/freertos/ringbuf.c

index cc1fccc925eb763108ad8b7969601002edeb0237..7cb24a5cae2733c740c243b55ca954f00cf19a9e 100644 (file)
@@ -602,16 +602,22 @@ BaseType_t xRingbufferSend(RingbufHandle_t ringbuf, void *data, size_t dataSize,
                 //we will need to wait some more.
                 if (ticks_to_wait != portMAX_DELAY) {
                     ticks_remaining = ticks_end - xTaskGetTickCount();
+
+                    // ticks_remaining will always be less than or equal to the original ticks_to_wait,
+                    // unless the timeout is reached - in which case it unsigned underflows to a much
+                    // higher value.
+                    //
+                    // (Check is written this non-intuitive way to allow for the case where xTaskGetTickCount()
+                    // has overflowed but the ticks_end value has not overflowed.)
+                    if(ticks_remaining > ticks_to_wait) {
+                        //Timeout, but there is not enough free space for the item that need to be sent.
+                        xSemaphoreGive(rb->free_space_sem);
+                        return pdFALSE;
+                    }
                 }
 
-                // ticks_remaining will always be less than or equal to the original ticks_to_wait,
-                // unless the timeout is reached - in which case it unsigned underflows to a much
-                // higher value.
-                //
-                // (Check is written this non-intuitive way to allow for the case where xTaskGetTickCount()
-                // has overflowed but the ticks_end value has not overflowed.)
             }
-        } while (ringbufferFreeMem(rb) < needed_size && ticks_remaining > 0 && ticks_remaining <= ticks_to_wait);
+        } while (ringbufferFreeMem(rb) < needed_size);
 
         //Lock the mux in order to make sure no one else is messing with the ringbuffer and do the copy.
         portENTER_CRITICAL(&rb->mux);