1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-12 01:53:07 +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

@ -177,20 +177,19 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
return _client->write(reinterpret_cast<const char*>(buf), size);
}
extern "C" uint32_t esp_micros_at_task_start();
extern "C" void optimistic_yield();
int WiFiClient::available()
{
static uint32_t lastPollTime = 0;
if (!_client)
return 0;
int result = 0;
if (lastPollTime > esp_micros_at_task_start())
yield();
if (_client) {
result = _client->getSize();
}
lastPollTime = micros();
int result = _client->getSize();
if (!result) {
optimistic_yield();
}
return result;
}