1
0
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:
Makuna
2015-07-13 13:47:13 -07:00
parent dece240830
commit d815c36753
7 changed files with 58 additions and 31 deletions

View File

@ -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) {