From b5b5844119ce061ae1bca809acd16232e2c1791e Mon Sep 17 00:00:00 2001 From: sg Date: Fri, 13 Feb 2015 21:53:55 +0100 Subject: [PATCH] added hook LWIP_HOOK_MEMP_AVAILABLE() to get informed when a memp pool was empty and an item is now available --- CHANGELOG | 4 ++++ src/core/memp.c | 17 ++++++++++++++--- src/include/lwip/opt.h | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 389e0916..7807d902 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,10 @@ HISTORY ++ New features: + 2015-02-13: Simon Goldschmidt + * opt.h, memp.c: added hook LWIP_HOOK_MEMP_AVAILABLE() to get informed when + a memp pool was empty and an item is now available + 2015-02-13: Simon Goldschmidt * opt.h, pbuf.h/.c, etharp.c: Added the option PBUF_LINK_ENCAPSULATION_HLEN to allocate additional header space for TX on netifs requiring additional headers diff --git a/src/core/memp.c b/src/core/memp.c index 3dbbec11..14e123e1 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -454,6 +454,9 @@ void memp_free(memp_t type, void *mem) { struct memp *memp; +#ifdef LWIP_HOOK_MEMP_AVAILABLE + struct memp *old_first; +#endif SYS_ARCH_DECL_PROTECT(old_level); if (mem == NULL) { @@ -474,9 +477,12 @@ memp_free(memp_t type, void *mem) #endif /* MEMP_OVERFLOW_CHECK >= 2 */ #endif /* MEMP_OVERFLOW_CHECK */ - MEMP_STATS_DEC(used, type); - - memp->next = memp_tab[type]; + MEMP_STATS_DEC(used, type); + + memp->next = memp_tab[type]; +#ifdef LWIP_HOOK_MEMP_AVAILABLE + old_first = memp_tab[type]; +#endif memp_tab[type] = memp; #if MEMP_SANITY_CHECK @@ -484,6 +490,11 @@ memp_free(memp_t type, void *mem) #endif /* MEMP_SANITY_CHECK */ SYS_ARCH_UNPROTECT(old_level); +#ifdef LWIP_HOOK_MEMP_AVAILABLE + if (old_first == NULL) { + LWIP_HOOK_MEMP_AVAILABLE(type); + } +#endif } #endif /* MEMP_MEM_MALLOC */ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 362a2176..bd834a40 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2547,6 +2547,11 @@ * Hook can be used to set prio_vid field of vlan_hdr. */ +/** + * LWIP_HOOK_MEMP_AVAILABLE(memp_t_type): + * - called from memp_free() when a memp pool was empty and an item is now available + */ + /* --------------------------------------- ---------- Debugging options ----------