From d4c8a1ac78024d25ea75dcb193988d1f668feb8c Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Wed, 31 May 2017 19:36:39 -0500 Subject: [PATCH] netconn: switch gethostbyname to use tcpip_send_msg_wait_sem (task #14523) This switches netconn_gethostbyname to use tcpip_send_msg_wait_sem to take advantage of core locking support when enabled. tcpip_send_msg_wait_sem handles blocking for the non-core locking case, so we can remove the manual blocking in netconn_gethostbyname. For the core locking case, we need to block if waiting on DNS callback. To achieve this, we unlock the core and wait in lwip_netconn_do_gethostbyname. This is the similar approach that netconn_write takes when it needs to block to continue the write (see lwip_netconn_do_write) This improves performance in the core locking case and is no change for the non-core locking case --- CHANGELOG | 3 +++ src/api/api_lib.c | 14 +++++--------- src/api/api_msg.c | 10 ++++++++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index fcd86b45..c38d23ef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,9 @@ HISTORY ++ New features: + 2017-06-20: Joel Cunningham + * netconn/netdb: added core locking support to netconn_gethostbyname (task #14523) + 2017-04-25: Simon Goldschmidt * dhcp: added two hooks for adding and parsing user defined DHCP options diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 0e0ac6fc..587ce38a 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -1184,18 +1184,14 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr) } #endif /* LWIP_NETCONN_SEM_PER_THREAD */ - cberr = tcpip_callback(lwip_netconn_do_gethostbyname, &API_VAR_REF(msg)); - if (cberr != ERR_OK) { -#if !LWIP_NETCONN_SEM_PER_THREAD - sys_sem_free(API_EXPR_REF(API_VAR_REF(msg).sem)); -#endif /* !LWIP_NETCONN_SEM_PER_THREAD */ - API_VAR_FREE(MEMP_DNS_API_MSG, msg); - return cberr; - } - sys_sem_wait(API_EXPR_REF_SEM(API_VAR_REF(msg).sem)); + cberr = tcpip_send_msg_wait_sem(lwip_netconn_do_gethostbyname, &API_VAR_REF(msg), API_EXPR_REF(API_VAR_REF(msg).sem)); #if !LWIP_NETCONN_SEM_PER_THREAD sys_sem_free(API_EXPR_REF(API_VAR_REF(msg).sem)); #endif /* !LWIP_NETCONN_SEM_PER_THREAD */ + if (cberr != ERR_OK) { + API_VAR_FREE(MEMP_DNS_API_MSG, msg); + return cberr; + } #if LWIP_MPU_COMPATIBLE *addr = msg->addr; diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 15b2e2a6..c2106b85 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -2042,11 +2042,21 @@ lwip_netconn_do_gethostbyname(void *arg) API_EXPR_DEREF(msg->err) = dns_gethostbyname_addrtype(msg->name, API_EXPR_REF(msg->addr), lwip_netconn_do_dns_found, msg, addrtype); +#if LWIP_TCPIP_CORE_LOCKING + /* For core locking, only block if we need to wait for answer/timeout */ + if (API_EXPR_DEREF(msg->err) == ERR_INPROGRESS) { + UNLOCK_TCPIP_CORE(); + sys_sem_wait(API_EXPR_REF_SEM(msg->sem)); + LOCK_TCPIP_CORE(); + LWIP_ASSERT("do_gethostbyname still in progress!!", API_EXPR_DEREF(msg->err) != ERR_INPROGRESS); + } +#else /* LWIP_TCPIP_CORE_LOCKING */ if (API_EXPR_DEREF(msg->err) != ERR_INPROGRESS) { /* on error or immediate success, wake up the application * task waiting in netconn_gethostbyname */ sys_sem_signal(API_EXPR_REF_SEM(msg->sem)); } +#endif /* LWIP_TCPIP_CORE_LOCKING */ } #endif /* LWIP_DNS */