diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 10df873b..b4e398ff 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -63,34 +63,32 @@ static err_t netconn_close_shutdown(struct netconn *conn, u8_t how); -#if !LWIP_TCPIP_CORE_LOCKING /** * Call the lower part of a netconn_* function * This function is then running in the thread context * of tcpip_thread and has exclusive access to lwIP core code. * + * @param fn function to call * @param apimsg a struct containing the function to call and its parameters * @return ERR_OK if the function was called, another err_t if not */ static err_t -tcpip_apimsg(struct api_msg *apimsg) +tcpip_apimsg(tcpip_callback_fn fn, struct api_msg *apimsg) { #ifdef LWIP_DEBUG /* catch functions that don't set err */ apimsg->msg.err = ERR_VAL; -#endif +#endif /* LWIP_DEBUG */ + #if LWIP_NETCONN_SEM_PER_THREAD apimsg->msg.op_completed_sem = LWIP_NETCONN_THREAD_SEM_GET(); - LWIP_ASSERT("netconn semaphore not initialized", - sys_sem_valid(apimsg->msg.op_completed_sem)); -#endif +#endif /* LWIP_NETCONN_SEM_PER_THREAD */ - if (tcpip_send_api_msg(apimsg->function, &apimsg->msg, LWIP_API_MSG_SEM(&apimsg->msg)) == ERR_OK) { + if (tcpip_send_api_msg(fn, &apimsg->msg, LWIP_API_MSG_SEM(&apimsg->msg)) == ERR_OK) { return apimsg->msg.err; } return ERR_VAL; } -#endif /* !LWIP_TCPIP_CORE_LOCKING */ /** * Create a new netconn (of a specific type) that has a callback function. @@ -114,7 +112,7 @@ netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, netconn_cal API_MSG_VAR_ALLOC_DONTFAIL(msg); API_MSG_VAR_REF(msg).msg.msg.n.proto = proto; API_MSG_VAR_REF(msg).msg.conn = conn; - TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_newconn, err); + err = tcpip_apimsg(lwip_netconn_do_newconn, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); if (err != ERR_OK) { LWIP_ASSERT("freeing conn without freeing pcb", conn->pcb.tcp == NULL); @@ -165,7 +163,7 @@ netconn_delete(struct netconn *conn) ((LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT + TCP_SLOW_INTERVAL - 1) / TCP_SLOW_INTERVAL) + 1; #endif /* LWIP_TCP */ #endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */ - TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_delconn, err); + err = tcpip_apimsg(lwip_netconn_do_delconn, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); if (err != ERR_OK) { @@ -208,7 +206,7 @@ netconn_getaddr(struct netconn *conn, ip_addr_t *addr, u16_t *port, u8_t local) #else /* LWIP_MPU_COMPATIBLE */ msg.msg.msg.ad.ipaddr = addr; msg.msg.msg.ad.port = port; - TCPIP_APIMSG(&msg, lwip_netconn_do_getaddr, err); + err = tcpip_apimsg(lwip_netconn_do_getaddr, &msg); #endif /* LWIP_MPU_COMPATIBLE */ API_MSG_VAR_FREE(msg); @@ -242,7 +240,7 @@ netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port) API_MSG_VAR_REF(msg).msg.conn = conn; API_MSG_VAR_REF(msg).msg.msg.bc.ipaddr = API_MSG_VAR_REF(addr); API_MSG_VAR_REF(msg).msg.msg.bc.port = port; - TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_bind, err); + err = tcpip_apimsg(lwip_netconn_do_bind, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); return err; @@ -273,7 +271,7 @@ netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port) API_MSG_VAR_REF(msg).msg.conn = conn; API_MSG_VAR_REF(msg).msg.msg.bc.ipaddr = API_MSG_VAR_REF(addr); API_MSG_VAR_REF(msg).msg.msg.bc.port = port; - TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_connect, err); + err = tcpip_apimsg(lwip_netconn_do_connect, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); return err; @@ -295,7 +293,7 @@ netconn_disconnect(struct netconn *conn) API_MSG_VAR_ALLOC(msg); API_MSG_VAR_REF(msg).msg.conn = conn; - TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_disconnect, err); + err = tcpip_apimsg(lwip_netconn_do_disconnect, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); return err; @@ -326,7 +324,7 @@ netconn_listen_with_backlog(struct netconn *conn, u8_t backlog) #if TCP_LISTEN_BACKLOG API_MSG_VAR_REF(msg).msg.msg.lb.backlog = backlog; #endif /* TCP_LISTEN_BACKLOG */ - TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_listen, err); + err = tcpip_apimsg(lwip_netconn_do_listen, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); return err; @@ -390,7 +388,7 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn) API_MSG_VAR_ALLOC_DONTFAIL(msg); API_MSG_VAR_REF(msg).msg.conn = conn; /* don't care for the return value of lwip_netconn_do_recv */ - TCPIP_APIMSG_NOERR(&API_MSG_VAR_REF(msg), lwip_netconn_do_recv); + tcpip_apimsg(lwip_netconn_do_recv, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); #endif /* TCP_LISTEN_BACKLOG */ @@ -473,7 +471,7 @@ netconn_recv_data(struct netconn *conn, void **new_buf) API_MSG_VAR_REF(msg).msg.msg.r.len = 1; } /* don't care for the return value of lwip_netconn_do_recv */ - TCPIP_APIMSG_NOERR(&API_MSG_VAR_REF(msg), lwip_netconn_do_recv); + tcpip_apimsg(lwip_netconn_do_recv, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); } @@ -612,7 +610,7 @@ netconn_recved(struct netconn *conn, u32_t length) API_MSG_VAR_REF(msg).msg.conn = conn; API_MSG_VAR_REF(msg).msg.msg.r.len = length; /* don't care for the return value of lwip_netconn_do_recv */ - TCPIP_APIMSG_NOERR(&API_MSG_VAR_REF(msg), lwip_netconn_do_recv); + tcpip_apimsg(lwip_netconn_do_recv, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); } #else /* LWIP_TCP */ @@ -661,7 +659,7 @@ netconn_send(struct netconn *conn, struct netbuf *buf) API_MSG_VAR_ALLOC(msg); API_MSG_VAR_REF(msg).msg.conn = conn; API_MSG_VAR_REF(msg).msg.msg.b = buf; - TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_send, err); + err = tcpip_apimsg(lwip_netconn_do_send, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); return err; @@ -719,7 +717,7 @@ netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size, /* For locking the core: this _can_ be delayed on low memory/low send buffer, but if it is, this is done inside api_msg.c:do_write(), so we can use the non-blocking version here. */ - TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_write, err); + err = tcpip_apimsg(lwip_netconn_do_write, &API_MSG_VAR_REF(msg)); if ((err == ERR_OK) && (bytes_written != NULL)) { if (dontblock #if LWIP_SO_SNDTIMEO @@ -768,7 +766,7 @@ netconn_close_shutdown(struct netconn *conn, u8_t how) ((LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT + TCP_SLOW_INTERVAL - 1) / TCP_SLOW_INTERVAL) + 1; #endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */ #endif /* LWIP_TCP */ - TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_close, err); + err = tcpip_apimsg(lwip_netconn_do_close, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); return err; @@ -835,7 +833,7 @@ netconn_join_leave_group(struct netconn *conn, API_MSG_VAR_REF(msg).msg.msg.jl.multiaddr = API_MSG_VAR_REF(multiaddr); API_MSG_VAR_REF(msg).msg.msg.jl.netif_addr = API_MSG_VAR_REF(netif_addr); API_MSG_VAR_REF(msg).msg.msg.jl.join_or_leave = join_or_leave; - TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_join_leave_group, err); + err = tcpip_apimsg(lwip_netconn_do_join_leave_group, &API_MSG_VAR_REF(msg)); API_MSG_VAR_FREE(msg); return err; diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 0bf6a800..85f8948c 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -77,6 +77,12 @@ static err_t lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM static err_t lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM); #endif +#if LWIP_TCPIP_CORE_LOCKING +#define TCPIP_APIMSG_ACK(m) NETCONN_SET_SAFE_ERR((m)->conn, (m)->err) +#else /* LWIP_TCPIP_CORE_LOCKING */ +#define TCPIP_APIMSG_ACK(m) do { NETCONN_SET_SAFE_ERR((m)->conn, (m)->err); sys_sem_signal(LWIP_API_MSG_SEM(m)); } while(0) +#endif /* LWIP_TCPIP_CORE_LOCKING */ + #if LWIP_RAW /** * Receive callback function for RAW netconns. diff --git a/src/include/lwip/priv/api_msg.h b/src/include/lwip/priv/api_msg.h index b2ef3370..9f8b17dd 100644 --- a/src/include/lwip/priv/api_msg.h +++ b/src/include/lwip/priv/api_msg.h @@ -154,8 +154,6 @@ struct api_msg_msg { a struct api_msg_msg that serves as an argument for this function. This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */ struct api_msg { - /** function to execute in tcpip_thread context */ - void (* function)(void *msg); /** arguments for this function */ struct api_msg_msg msg; }; @@ -186,35 +184,6 @@ struct dns_api_msg { }; #endif /* LWIP_DNS */ -#if LWIP_TCPIP_CORE_LOCKING -#ifdef LWIP_DEBUG -#define TCIP_APIMSG_SET_ERR(m, e) (m)->msg.err = e /* catch functions that don't set err */ -#else -#define TCIP_APIMSG_SET_ERR(m, e) -#endif -#if LWIP_NETCONN_SEM_PER_THREAD -#define TCPIP_APIMSG_SET_SEM(m) ((m)->msg.op_completed_sem = LWIP_NETCONN_THREAD_SEM_GET()) -#else -#define TCPIP_APIMSG_SET_SEM(m) -#endif -#define TCPIP_APIMSG_NOERR(m,f) do { \ - TCIP_APIMSG_SET_ERR(m, ERR_VAL); \ - TCPIP_APIMSG_SET_SEM(m); \ - LOCK_TCPIP_CORE(); \ - f(&((m)->msg)); \ - UNLOCK_TCPIP_CORE(); \ -} while(0) -#define TCPIP_APIMSG(m,f,e) do { \ - TCPIP_APIMSG_NOERR(m,f); \ - (e) = (m)->msg.err; \ -} while(0) -#define TCPIP_APIMSG_ACK(m) NETCONN_SET_SAFE_ERR((m)->conn, (m)->err) -#else /* LWIP_TCPIP_CORE_LOCKING */ -#define TCPIP_APIMSG_NOERR(m,f) do { (m)->function = f; tcpip_apimsg(m); } while(0) -#define TCPIP_APIMSG(m,f,e) do { (m)->function = f; (e) = tcpip_apimsg(m); } while(0) -#define TCPIP_APIMSG_ACK(m) do { NETCONN_SET_SAFE_ERR((m)->conn, (m)->err); sys_sem_signal(LWIP_API_MSG_SEM(m)); } while(0) -#endif /* LWIP_TCPIP_CORE_LOCKING */ - void lwip_netconn_do_newconn (void *m); void lwip_netconn_do_delconn (void *m); void lwip_netconn_do_bind (void *m);