mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-11 15:22:13 +03:00
optimistic_yield()
this introduces optimistic_yield() used for when standard library methods are normally used in tight loops waiting for something to happen, like available().
This commit is contained in:
@ -551,14 +551,20 @@ bool HardwareSerial::isRxEnabled(void) {
|
||||
return _uart->rxEnabled;
|
||||
}
|
||||
|
||||
extern "C" void optimistic_yield();
|
||||
|
||||
int HardwareSerial::available(void) {
|
||||
if(_uart == 0)
|
||||
return 0;
|
||||
if(_uart->rxEnabled) {
|
||||
return static_cast<int>(_rx_buffer->getSize());
|
||||
} else {
|
||||
return 0;
|
||||
int result = 0;
|
||||
|
||||
if (_uart != NULL && _uart->rxEnabled) {
|
||||
result = static_cast<int>(_rx_buffer->getSize());
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
optimistic_yield();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int HardwareSerial::peek(void) {
|
||||
|
Reference in New Issue
Block a user