From 7e7f2f31ff4515417ed9c9ca1ee84cd0867691ff Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 22 Mar 2016 21:52:11 +0100 Subject: [PATCH] Cleanup and simplify tcpip_api_call() implementation a bit --- src/api/tcpip.c | 29 ++++++++++++++--------------- src/include/lwip/priv/tcpip_priv.h | 18 ++++++++++-------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 163ac09f..9dfdec12 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -105,12 +105,8 @@ tcpip_thread(void *arg) break; case TCPIP_MSG_API_CALL: LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API CALL message %p\n", (void *)msg)); - msg->msg.api_call->err = msg->msg.api_call->function(msg->msg.api_call); -#if LWIP_NETCONN_SEM_PER_THREAD - sys_sem_signal(msg->msg.api_call->sem); -#else /* LWIP_NETCONN_SEM_PER_THREAD */ - sys_sem_signal(&msg->msg.api_call->sem); -#endif /* LWIP_NETCONN_SEM_PER_THREAD */ + msg->msg.api_call.arg->err = msg->msg.api_call.function(msg->msg.api_call.arg); + sys_sem_signal(msg->msg.api_call.sem); break; #endif /* !LWIP_TCPIP_CORE_LOCKING */ @@ -376,9 +372,7 @@ tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call) TCPIP_MSG_VAR_DECLARE(msg); err_t err; -#if LWIP_NETCONN_SEM_PER_THREAD - call->sem = LWIP_NETCONN_THREAD_SEM_GET(); -#else /* LWIP_NETCONN_SEM_PER_THREAD */ +#if !LWIP_NETCONN_SEM_PER_THREAD err = sys_sem_new(&call->sem, 0); if (err != ERR_OK) { return err; @@ -387,16 +381,21 @@ tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call) TCPIP_MSG_VAR_ALLOC(msg); TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API_CALL; - TCPIP_MSG_VAR_REF(msg).msg.api_call = call; - TCPIP_MSG_VAR_REF(msg).msg.api_call->function = fn; - sys_mbox_post(&mbox, &TCPIP_MSG_VAR_REF(msg)); + TCPIP_MSG_VAR_REF(msg).msg.api_call.arg = call; + TCPIP_MSG_VAR_REF(msg).msg.api_call.function = fn; #if LWIP_NETCONN_SEM_PER_THREAD - sys_arch_sem_wait(call->sem, 0); + TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = LWIP_NETCONN_THREAD_SEM_GET(); #else /* LWIP_NETCONN_SEM_PER_THREAD */ - sys_arch_sem_wait(&call->sem, 0); + TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = &call->sem; +#endif /* LWIP_NETCONN_SEM_PER_THREAD */ + sys_mbox_post(&mbox, &TCPIP_MSG_VAR_REF(msg)); + sys_arch_sem_wait(TCPIP_MSG_VAR_REF(msg).msg.api_call.sem, 0); + TCPIP_MSG_VAR_FREE(msg); + +#if !LWIP_NETCONN_SEM_PER_THREAD sys_sem_free(&call->sem); #endif /* LWIP_NETCONN_SEM_PER_THREAD */ - TCPIP_MSG_VAR_FREE(msg); + return call->err; } return ERR_VAL; diff --git a/src/include/lwip/priv/tcpip_priv.h b/src/include/lwip/priv/tcpip_priv.h index 687f6d75..660a8535 100644 --- a/src/include/lwip/priv/tcpip_priv.h +++ b/src/include/lwip/priv/tcpip_priv.h @@ -97,20 +97,18 @@ extern sys_mutex_t lock_tcpip_core; err_t tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem); -struct tcpip_api_call; -typedef err_t (*tcpip_api_call_fn)(struct tcpip_api_call* call); struct tcpip_api_call { - tcpip_api_call_fn function; #if !LWIP_TCPIP_CORE_LOCKING -#if LWIP_NETCONN_SEM_PER_THREAD - sys_sem_t *sem; -#else /* LWIP_NETCONN_SEM_PER_THREAD */ + err_t err; +#if !LWIP_NETCONN_SEM_PER_THREAD sys_sem_t sem; #endif /* LWIP_NETCONN_SEM_PER_THREAD */ - err_t err; +#else /* !LWIP_TCPIP_CORE_LOCKING */ + u8_t dummy; /* avoid empty struct :-( */ #endif /* !LWIP_TCPIP_CORE_LOCKING */ }; +typedef err_t (*tcpip_api_call_fn)(struct tcpip_api_call* call); err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call *call); enum tcpip_msg_type { @@ -132,7 +130,11 @@ struct tcpip_msg { tcpip_callback_fn function; void* msg; } api_msg; - struct tcpip_api_call *api_call; + struct { + tcpip_api_call_fn function; + struct tcpip_api_call *arg; + sys_sem_t *sem; + } api_call; struct { struct pbuf *p; struct netif *netif;