Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of memory callback #418

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions common/platforms/esp8266/esp_umm_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 4 additions & 0 deletions common/platforms/esp8266/esp_umm_malloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */