fix(sntp): Lock / Unlock LWIP if CONFIG_LWIP_TCPIP_CORE_LOCKING is set (#10529)

* fix(sntp): Lock / Unlock LWIP if CONFIG_LWIP_TCPIP_CORE_LOCKING is set
Fixes: https://github.com/espressif/arduino-esp32/issues/10526

* ci(pre-commit): Apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
Mathieu Carbou 2024-10-29 12:10:40 +01:00 committed by GitHub
parent 74e4a744ce
commit d47771f2cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,6 +17,10 @@
//#include "tcpip_adapter.h" //#include "tcpip_adapter.h"
#include "esp_netif.h" #include "esp_netif.h"
#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
#include "lwip/priv/tcpip_priv.h"
#endif
static void setTimeZone(long offset, int daylight) { static void setTimeZone(long offset, int daylight) {
char cst[17] = {0}; char cst[17] = {0};
char cdt[17] = "DST"; char cdt[17] = "DST";
@ -50,11 +54,25 @@ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char *server1,
if (sntp_enabled()) { if (sntp_enabled()) {
sntp_stop(); sntp_stop();
} }
#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) {
LOCK_TCPIP_CORE();
}
#endif
sntp_setoperatingmode(SNTP_OPMODE_POLL); sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, (char *)server1); sntp_setservername(0, (char *)server1);
sntp_setservername(1, (char *)server2); sntp_setservername(1, (char *)server2);
sntp_setservername(2, (char *)server3); sntp_setservername(2, (char *)server3);
sntp_init(); sntp_init();
#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) {
UNLOCK_TCPIP_CORE();
}
#endif
setTimeZone(-gmtOffset_sec, daylightOffset_sec); setTimeZone(-gmtOffset_sec, daylightOffset_sec);
} }
@ -68,11 +86,25 @@ void configTzTime(const char *tz, const char *server1, const char *server2, cons
if (sntp_enabled()) { if (sntp_enabled()) {
sntp_stop(); sntp_stop();
} }
#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) {
LOCK_TCPIP_CORE();
}
#endif
sntp_setoperatingmode(SNTP_OPMODE_POLL); sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, (char *)server1); sntp_setservername(0, (char *)server1);
sntp_setservername(1, (char *)server2); sntp_setservername(1, (char *)server2);
sntp_setservername(2, (char *)server3); sntp_setservername(2, (char *)server3);
sntp_init(); sntp_init();
#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) {
UNLOCK_TCPIP_CORE();
}
#endif
setenv("TZ", tz, 1); setenv("TZ", tz, 1);
tzset(); tzset();
} }