From ee32bdc3360cb5a73f9e491252bc0f0931a911c6 Mon Sep 17 00:00:00 2001 From: Chen Wen Date: Fri, 9 Nov 2018 17:42:53 +0800 Subject: [PATCH] feat(lwip): Add to prevent switch to tcpip thread between mbox post and sem wait --- components/lwip/lwip/src/api/tcpip.c | 9 +++++++++ .../lwip/port/esp8266/freertos/sys_arch.c | 10 ++++++++++ .../lwip/port/esp8266/include/arch/sys_arch.h | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/components/lwip/lwip/src/api/tcpip.c b/components/lwip/lwip/src/api/tcpip.c index 1f3fb61c..e229f333 100644 --- a/components/lwip/lwip/src/api/tcpip.c +++ b/components/lwip/lwip/src/api/tcpip.c @@ -344,8 +344,17 @@ tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem) TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API; TCPIP_MSG_VAR_REF(msg).msg.api_msg.function = fn; TCPIP_MSG_VAR_REF(msg).msg.api_msg.msg = apimsg; +#if ESP_LWIP + u8_t prio = sys_thread_priority_get(NULL); // add to prevent switch to tcpip thread between mbox post and sem wait + if((TCPIP_THREAD_PRIO + 1) > prio) { + sys_thread_priority_set(NULL, TCPIP_THREAD_PRIO + 1); // set priority higher than tcpip thread + } +#endif sys_mbox_post(&mbox, &TCPIP_MSG_VAR_REF(msg)); sys_arch_sem_wait(sem, 0); +#if ESP_LWIP + sys_thread_priority_set(NULL, prio); +#endif TCPIP_MSG_VAR_FREE(msg); return ERR_OK; #endif /* LWIP_TCPIP_CORE_LOCKING */ diff --git a/components/lwip/port/esp8266/freertos/sys_arch.c b/components/lwip/port/esp8266/freertos/sys_arch.c index e3bc1b4c..c4718b79 100644 --- a/components/lwip/port/esp8266/freertos/sys_arch.c +++ b/components/lwip/port/esp8266/freertos/sys_arch.c @@ -438,6 +438,16 @@ sys_arch_msleep(int ms) vTaskDelay(ms / portTICK_RATE_MS); } +u8_t sys_thread_priority_get(sys_thread_t thread_handle) +{ + return (u8_t)uxTaskPriorityGet(thread_handle); +} + +void sys_thread_priority_set(sys_thread_t thread_handle, u8_t priority) +{ + vTaskPrioritySet(thread_handle, (UBaseType_t)priority); +} + #if LWIP_NETCONN_SEM_PER_THREAD static void sys_thread_sem_free(int index, void *data) // destructor for TLS semaphore diff --git a/components/lwip/port/esp8266/include/arch/sys_arch.h b/components/lwip/port/esp8266/include/arch/sys_arch.h index 4b3bd8a8..a1a5c3bf 100644 --- a/components/lwip/port/esp8266/include/arch/sys_arch.h +++ b/components/lwip/port/esp8266/include/arch/sys_arch.h @@ -48,6 +48,24 @@ typedef xTaskHandle sys_thread_t; #define sys_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) #define sys_sem_set_invalid( x ) ( ( *x ) = NULL ) +/** + * Get thread priority througth thread_handle + * + * @param task_handle + * + * @return thread priority + */ +u8_t sys_thread_priority_get(sys_thread_t thread_handle); + +/** + * Set thread priority througth thread_handle + * + * @param task_handle + * + * @param priority + */ +void sys_thread_priority_set(sys_thread_t thread_handle, u8_t priority); + #define LWIP_COMPAT_MUTEX 0 #if LWIP_NETCONN_SEM_PER_THREAD