1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-10 04:22:05 +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

@ -113,12 +113,22 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
return 1;
}
extern "C" void optimistic_yield();
/* return number of bytes available in the current packet,
will return zero if parsePacket hasn't been called yet */
int WiFiUDP::available() {
if (!_ctx)
return 0;
return static_cast<int>(_ctx->getSize());
int result = 0;
if (_ctx) {
result = static_cast<int>(_ctx->getSize());
}
if (!result) {
optimistic_yield();
}
return result;
}
/* Release any resources being used by this WiFiUDP instance */