mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #7948 from kegilbert/mbed_mem_trace_log_toggle
Add enable/disable cb function in mem_tracepull/8272/head
commit
ad6ada014a
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue