diff --git a/components/lwip/lwip b/components/lwip/lwip index 4297782bf9..aa4f6e780f 160000 --- a/components/lwip/lwip +++ b/components/lwip/lwip @@ -1 +1 @@ -Subproject commit 4297782bf9e614be1bb8605f30d46af8697fab17 +Subproject commit aa4f6e780f374af5e10730960fe0262a916166d1 diff --git a/components/lwip/port/freertos/include/arch/sys_arch.h b/components/lwip/port/freertos/include/arch/sys_arch.h index f945a14c0c..408f9e7990 100644 --- a/components/lwip/port/freertos/include/arch/sys_arch.h +++ b/components/lwip/port/freertos/include/arch/sys_arch.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-3-Clause * - * SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD */ #ifndef __SYS_ARCH_H__ #define __SYS_ARCH_H__ @@ -24,7 +24,6 @@ typedef TaskHandle_t sys_thread_t; typedef struct sys_mbox_s { QueueHandle_t os_mbox; - void *owner; }* sys_mbox_t; /** This is returned by _fromisr() sys functions to tell the outermost function @@ -38,33 +37,17 @@ void sys_delay_ms(uint32_t ms); #define LWIP_COMPAT_MUTEX 0 #if !LWIP_COMPAT_MUTEX -#define sys_mutex_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) -#define sys_mutex_set_invalid( x ) ( ( *x ) = NULL ) +#define sys_mutex_valid_val(mutex) ((mutex) != NULL) +#define sys_mutex_valid(mutex) (((mutex) != NULL) && sys_mutex_valid_val(*(mutex))) +#define sys_mutex_set_invalid(mutex) ((*(mutex)) = NULL) #endif -#define sys_mbox_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) +#define sys_mbox_valid(mbox) (*(mbox) != NULL) +#define sys_mbox_set_invalid(mbox) (*(mbox) = NULL) -/* Define the sys_mbox_set_invalid() to empty to support lock-free mbox in ESP LWIP. - * - * The basic idea about the lock-free mbox is that the mbox should always be valid unless - * no socket APIs are using the socket and the socket is closed. ESP LWIP achieves this by - * following two changes to official LWIP: - * 1. Postpone the deallocation of mbox to netconn_free(), in other words, free the mbox when - * no one is using the socket. - * 2. Define the sys_mbox_set_invalid() to empty if the mbox is not actually freed. - - * The second change is necessary. Consider a common scenario: the application task calls - * recv() to receive packets from the socket, the sys_mbox_valid() returns true. Because there - * is no lock for the mbox, the LWIP CORE can call sys_mbox_set_invalid() to set the mbox at - * anytime and the thread-safe issue may happen. - * - * However, if the sys_mbox_set_invalid() is not called after sys_mbox_free(), e.g. in netconn_alloc(), - * we need to initialize the mbox to invalid explicitly since sys_mbox_set_invalid() now is empty. - */ -#define sys_mbox_set_invalid( x ) *x = NULL - -#define sys_sem_valid( x ) ( ( (x) == NULL ) ? pdFALSE : ( ( *x ) == NULL ? pdFALSE : pdTRUE ) ) -#define sys_sem_set_invalid( x ) ( ( *x ) = NULL ) +#define sys_sem_valid_val(sema) ((sema) != NULL) +#define sys_sem_valid(sema) (((sema) != NULL) && sys_sem_valid_val(*(sema))) +#define sys_sem_set_invalid(sema) ((*(sema)) = NULL) void sys_delay_ms(uint32_t ms); sys_sem_t* sys_thread_sem_init(void); diff --git a/components/lwip/port/freertos/sys_arch.c b/components/lwip/port/freertos/sys_arch.c index 0f8cb26376..a7a48d08b7 100644 --- a/components/lwip/port/freertos/sys_arch.c +++ b/components/lwip/port/freertos/sys_arch.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: BSD-3-Clause * - * SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD */ /* lwIP includes. */ @@ -219,10 +219,6 @@ sys_mbox_new(sys_mbox_t *mbox, int size) return ERR_MEM; } -#if ESP_THREAD_SAFE - (*mbox)->owner = NULL; -#endif - LWIP_DEBUGF(ESP_THREAD_SAFE_DEBUG, ("new *mbox ok mbox=%p os_mbox=%p\n", *mbox, (*mbox)->os_mbox)); return ERR_OK; } @@ -352,15 +348,6 @@ sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) return 0; } -void -sys_mbox_set_owner(sys_mbox_t *mbox, void* owner) -{ - if (mbox && *mbox) { - (*mbox)->owner = owner; - LWIP_DEBUGF(ESP_THREAD_SAFE_DEBUG, ("set mbox=%p owner=%p", *mbox, owner)); - } -} - /** * @brief Delete a mailbox * @@ -444,7 +431,7 @@ sys_jiffies(void) } /** - * @brief Get current time, in miliseconds + * @brief Get current time, in milliseconds * * @return current time */ diff --git a/components/lwip/port/include/lwipopts.h b/components/lwip/port/include/lwipopts.h index e95d647029..48feeb16c3 100644 --- a/components/lwip/port/include/lwipopts.h +++ b/components/lwip/port/include/lwipopts.h @@ -1592,7 +1592,7 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) #define ESP_LWIP 1 #define ESP_LWIP_ARP 1 #define ESP_PER_SOC_TCP_WND 0 -#define ESP_THREAD_SAFE 1 +#define ESP_THREAD_SAFE 1 /* Not used (to be removed in v6.x) */ #define ESP_THREAD_SAFE_DEBUG LWIP_DBG_OFF #define ESP_DHCP 1 #define ESP_DNS 1 @@ -1630,12 +1630,10 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) #if LWIP_NETCONN_SEM_PER_THREAD -#if ESP_THREAD_SAFE #define LWIP_NETCONN_THREAD_SEM_GET() sys_thread_sem_get() #define LWIP_NETCONN_THREAD_SEM_ALLOC() sys_thread_sem_init() #define LWIP_NETCONN_THREAD_SEM_FREE() sys_thread_sem_deinit() #endif -#endif /** * If CONFIG_ALLOC_MEMORY_IN_SPIRAM_FIRST is enabled, Try to