Skip to content

Commit 05d4eca

Browse files
author
Bogdan Pricop
committed
CDC-ACM: avoid race condition.
* In case bool() is called in a very tight while loop, give LMT space to set the host_open shared variable. Signed-off-by: Bogdan Pricop <bogdan.pricop@emutex.com>
1 parent b8d9b11 commit 05d4eca

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cores/arduino/CDCSerialClass.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "HardwareSerial.h"
2727
#include "platform.h"
28+
#include "wiring.h"
2829

2930
#include <board.h>
3031
#include <uart.h>
@@ -47,7 +48,12 @@ class CDCSerialClass : public HardwareSerial
4748
size_t write(const uint8_t c);
4849
using Print::write; // pull in write(str) and write(buf, size) from Print
4950

50-
operator bool() { return (_shared_data && _shared_data->host_open); };
51+
operator bool() {
52+
/* In case bool() is called in a very tight while loop, give LMT space
53+
* to set the variable */
54+
delay(1);
55+
return (_shared_data && _shared_data->host_open);
56+
};
5157

5258
protected:
5359
void init(const uint32_t dwBaudRate, const uint8_t config);

0 commit comments

Comments
 (0)