From ea174560b1350454f8c2c9f5494ab9331bac4665 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 16 Mar 2016 20:14:52 +0100 Subject: [PATCH] tcpip.c tcpip_send_api_msg: Handle core locking case internally --- src/api/tcpip.c | 22 +++++++++++++++------- src/include/lwip/priv/tcpip_priv.h | 2 -- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 73563b7d..de4842b0 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -312,10 +312,11 @@ tcpip_untimeout(sys_timeout_handler h, void *arg) #endif /* LWIP_TCPIP_TIMEOUT */ -#if !LWIP_TCPIP_CORE_LOCKING /** - * Generic way to dispatch an API message in TCPIP thread and wait for its - * completion by blocking on a semaphore. + * Synchronously calls function in TCPIP thread and waits for its completion + * by blocking on a provided semaphore pointer. + * It is recommended to use LWIP_TCPIP_CORE_LOCKING since this is the way + * with least runtime overhead. * * @param fn function to be called from TCPIP thread * @param apimsg argument to API function @@ -327,6 +328,13 @@ tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem) { LWIP_ASSERT("semaphore not initialized", sys_sem_valid(sem)); +#if LWIP_TCPIP_CORE_LOCKING + LOCK_TCPIP_CORE(); + fn(apimsg); + UNLOCK_TCPIP_CORE(); + sys_arch_sem_wait(sem, 0); + return ERR_OK; +#else /* LWIP_TCPIP_CORE_LOCKING */ if (sys_mbox_valid_val(mbox)) { TCPIP_MSG_VAR_DECLARE(msg); @@ -340,13 +348,13 @@ tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem) return ERR_OK; } return ERR_VAL; +#endif /* LWIP_TCPIP_CORE_LOCKING */ } -#endif /* !LWIP_TCPIP_CORE_LOCKING */ /** * Synchronously calls function in TCPIP thread and waits for its completion. * It is recommended to use LWIP_TCPIP_CORE_LOCKING (preferred) or - * LWIP_NETCONN_SEM_PER_THREAD. + * LWIP_NETCONN_SEM_PER_THREAD. * If not, a semaphore is created and destroyed on every call which is usually * an expensive/slow operation. * @param fn Function to call @@ -361,7 +369,7 @@ err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call) err = fn(call); UNLOCK_TCPIP_CORE(); return err; -#else +#else /* LWIP_TCPIP_CORE_LOCKING */ if (sys_mbox_valid_val(mbox)) { TCPIP_MSG_VAR_DECLARE(msg); err_t err; @@ -390,7 +398,7 @@ err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call) return ERR_OK; } return ERR_VAL; -#endif +#endif /* LWIP_TCPIP_CORE_LOCKING */ } /** diff --git a/src/include/lwip/priv/tcpip_priv.h b/src/include/lwip/priv/tcpip_priv.h index cc1c54eb..24c19a56 100644 --- a/src/include/lwip/priv/tcpip_priv.h +++ b/src/include/lwip/priv/tcpip_priv.h @@ -95,9 +95,7 @@ extern sys_mutex_t lock_tcpip_core; #define API_EXPR_DEREF(expr) *(expr) #endif /* LWIP_MPU_COMPATIBLE */ -#if !LWIP_TCPIP_CORE_LOCKING err_t tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem); -#endif /* !LWIP_TCPIP_CORE_LOCKING */ struct tcpip_api_call; typedef err_t (*tcpip_api_call_fn)(struct tcpip_api_call* call);