From 7c2f736bd80b8bbbeaca95668f1942be7eb3265e Mon Sep 17 00:00:00 2001 From: Michael Glettig Date: Mon, 9 Apr 2018 13:09:58 +0200 Subject: [PATCH] Added: Possibility to register a user callback function that is called in out of memory case (for ESP8266). --- common/platforms/esp8266/esp_umm_malloc.c | 9 +++++++++ common/platforms/esp8266/esp_umm_malloc.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/common/platforms/esp8266/esp_umm_malloc.c b/common/platforms/esp8266/esp_umm_malloc.c index 15869a712..9df49f3e2 100644 --- a/common/platforms/esp8266/esp_umm_malloc.c +++ b/common/platforms/esp8266/esp_umm_malloc.c @@ -112,9 +112,18 @@ void esp_umm_init(void) { /* Nothing to do, see header for details */ } +static esp_umm_malloc_OutOfMemoryCallback_t outOfMemoryCallback = NULL; + +void esp_umm_oom_register_OutOfMemoryCallback(esp_umm_malloc_OutOfMemoryCallback_t callback) { + outOfMemoryCallback = callback; +} + void esp_umm_oom_cb(size_t size, size_t blocks_cnt) { fprintf(stderr, "E:M %u (%u blocks)\n", (unsigned int) size, (unsigned int) blocks_cnt); + if( outOfMemoryCallback != NULL ) { + outOfMemoryCallback(size, blocks_cnt); + } } #endif /* ESP_UMM_ENABLE */ diff --git a/common/platforms/esp8266/esp_umm_malloc.h b/common/platforms/esp8266/esp_umm_malloc.h index f838e4f3d..8c409a7ab 100644 --- a/common/platforms/esp8266/esp_umm_malloc.h +++ b/common/platforms/esp8266/esp_umm_malloc.h @@ -32,4 +32,8 @@ void esp_umm_init(void); */ void esp_umm_oom_cb(size_t size, size_t blocks_cnt); +typedef void (*esp_umm_malloc_OutOfMemoryCallback_t) (size_t size, size_t blocks_cnt); + +void esp_umm_oom_register_OutOfMemoryCallback(esp_umm_malloc_OutOfMemoryCallback_t callback); + #endif /* CS_COMMON_PLATFORMS_ESP8266_ESP_UMM_MALLOC_H_ */