mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
Implement esp_yield() as a replacement for delay(0)
esp_yield() now also calls esp_schedule(), original esp_yield() function renamed to esp_suspend(). Don't use delay(0) in the Core internals, libraries and examples. Use yield() when the code is supposed to be called from CONT, use esp_yield() when the code can be called from either CONT or SYS. Clean-up esp_yield() and esp_schedule() declarations across the code and use coredecls.h instead. Implement helper functions for libraries that were previously using esp_yield(), esp_schedule() and esp_delay() directly to wait for certain SYS context tasks to complete. Correctly use esp_delay() for timeouts, make sure scheduled functions have a chance to run (e.g. LwIP_Ethernet uses recurrent) Related issues: - #6107 - discussion about the esp_yield() and esp_delay() usage in ClientContext - #6212 - discussion about replacing delay() with a blocking loop - #6680 - pull request introducing LwIP-based Ethernet - #7146 - discussion that originated UART code changes - #7969 - proposal to remove delay(0) from the example code - #8291 - discussion related to the run_scheduled_recurrent_functions() usage in LwIP Ethernet - #8317 - yieldUntil() implementation, similar to the esp_delay() overload with a timeout and a 0 interval
This commit is contained in:
@ -22,6 +22,7 @@
|
||||
*
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
#include <coredecls.h>
|
||||
|
||||
#include "ESP8266HTTPClient.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
@ -556,6 +557,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size)
|
||||
if (transferred != size)
|
||||
{
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] short write, asked for %d but got %d failed.\n", size, transferred);
|
||||
esp_yield();
|
||||
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
|
||||
}
|
||||
|
||||
@ -698,7 +700,7 @@ int HTTPClient::writeToPrint(Print * print)
|
||||
return returnError(HTTPC_ERROR_READ_TIMEOUT);
|
||||
}
|
||||
|
||||
delay(0);
|
||||
esp_yield();
|
||||
}
|
||||
} else {
|
||||
return returnError(HTTPC_ERROR_ENCODING);
|
||||
@ -1060,7 +1062,7 @@ int HTTPClient::handleHeaderResponse()
|
||||
if((millis() - lastDataTime) > _tcpTimeout) {
|
||||
return HTTPC_ERROR_READ_TIMEOUT;
|
||||
}
|
||||
delay(0);
|
||||
esp_yield();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user