From 05587f5da9e7df8a8d9b50f573f8bff9e7df59e3 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 28 Mar 2008 07:56:47 +0000 Subject: [PATCH] Changed the pbuf_free/mem_free callback functions a little: created extra functions for that --- CHANGELOG | 5 ++--- src/api/tcpip.c | 37 +++++++++++++++++++++++++++++++------ src/include/lwip/opt.h | 4 ++-- src/include/lwip/tcpip.h | 4 ++-- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1fa23383..642c415d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -25,9 +25,8 @@ HISTORY 2008-03-27 Simon Goldschmidt * mem.c, tcpip.c, tcpip.h, opt.h: fixed bug #21433 (Calling mem_free/pbuf_free from interrupt context isn't safe): set LWIP_USE_HEAP_FROM_INTERRUPT to 1 - in lwipopts.h or use tcpip_callback_nonblocking(pbuf_free_int, p)/ - tcpip_callback_nonblocking(mem_free, m) to free pbufs or heap memory from - interrupt context + in lwipopts.h or use pbuf_free_callback(p)/mem_free_callback(m) to free pbufs + or heap memory from interrupt context 2008-03-26 Simon Goldschmidt * tcp_in.c, tcp.c: fixed bug #22249: division by zero could occur if a remote diff --git a/src/api/tcpip.c b/src/api/tcpip.c index b988ed1a..37b2e652 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -518,17 +518,42 @@ tcpip_init(void (* initfunc)(void *), void *arg) sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO); } - /** - * A simple wrapper function that allows you to free a pbuf using one of the - * tcpip_callback functions. + * Simple callback function used with tcpip_callback to free a pbuf + * (pbuf_free has a wrong signature for tcpip_callback) * * @param p The pbuf (chain) to be dereferenced. */ -void -pbuf_free_int(struct pbuf *p) +static void +pub_free_int(void *p) { - pbuf_free(p); + struct pbuf *q = p; + pbuf_free(q); +} + +/** + * A simple wrapper function that allows you to free a pbuf from interrupt context. + * + * @param p The pbuf (chain) to be dereferenced. + * @return ERR_OK if callback could be enqueued, an err_t if not + */ +err_t +pbuf_free_callback(struct pbuf *p) +{ + return tcpip_callback_with_block(pub_free_int, p, 0); +} + +/** + * A simple wrapper function that allows you to free heap memory from + * interrupt context. + * + * @param m the heap memory to free + * @return ERR_OK if callback could be enqueued, an err_t if not + */ +err_t +mem_free_callback(void *m) +{ + return tcpip_callback_with_block(mem_free, m, 0); } #endif /* !NO_SYS */ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index cf9e91f5..1f7b6ab5 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -166,8 +166,8 @@ * *** USE THIS WITH CARE: Setting this to 1 can disable interrupts for a long time! *** * * If you don't want that, call - * - tcpip_callback_nonblocking(pbuf_free_int, p); - * - tcpip_callback_nonblocking(mem_free, m); + * - pbuf_free_callback(p); + * - mem_free_callback(m); */ #ifndef LWIP_USE_HEAP_FROM_INTERRUPT #define LWIP_USE_HEAP_FROM_INTERRUPT 0 diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h index 2eb96749..cb0fe0eb 100644 --- a/src/include/lwip/tcpip.h +++ b/src/include/lwip/tcpip.h @@ -84,9 +84,9 @@ err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg); err_t tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block); #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1) -#define tcpip_callback_nonblocking(f, ctx) tcpip_callback_with_block(f, ctx, 0) -void pbuf_free_int(struct pbuf *p); +err_t pbuf_free_callback(struct pbuf *p); +err_t mem_free_callback(void *m); err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg); #define tcpip_untimeout(h, arg) tcpip_timeout(0xffffffff, h, arg)