diff --git a/platform/mbed_mem_trace.cpp b/platform/mbed_mem_trace.cpp index 7b7b3aa323..f34453cfd3 100644 --- a/platform/mbed_mem_trace.cpp +++ b/platform/mbed_mem_trace.cpp @@ -28,6 +28,7 @@ /* The callback function that will be called after a traced memory operations finishes. */ static mbed_mem_trace_cb_t mem_trace_cb; +static mbed_mem_trace_cb_t mem_trace_cb_reserve; /* 'trace_lock_count' guards "trace inside trace" situations (for example, the implementation * of realloc() might call malloc() internally, and since malloc() is also traced, this could * result in two calls to the callback function instead of one. */ @@ -46,6 +47,24 @@ void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb) mem_trace_cb = cb; } +void mbed_mem_trace_disable() +{ + mbed_mem_trace_lock(); + if (mem_trace_cb) { + mem_trace_cb_reserve = mem_trace_cb; + mem_trace_cb = 0; + } + mbed_mem_trace_unlock(); +} +void mbed_mem_trace_enable() +{ + mbed_mem_trace_lock(); + if (!mem_trace_cb && mem_trace_cb_reserve) { + mem_trace_cb = mem_trace_cb_reserve; + } + mbed_mem_trace_unlock(); +} + void mbed_mem_trace_lock() { mem_trace_mutex->lock(); diff --git a/platform/mbed_mem_trace.h b/platform/mbed_mem_trace.h index 7e9d1f1401..047fef9164 100644 --- a/platform/mbed_mem_trace.h +++ b/platform/mbed_mem_trace.h @@ -74,6 +74,16 @@ typedef void (*mbed_mem_trace_cb_t)(uint8_t op, void *res, void *caller, ...); */ void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb); +/** + * Disable the memory trace output by disabling the callback function + */ +void mbed_mem_trace_disable(); + +/** + * Renable the memory trace output with the cb in use when disable was called + */ +void mbed_mem_trace_enable(); + /** * Trace lock. * @note Locking prevent recursive tracing of malloc/free inside relloc/calloc