Merge pull request #7948 from kegilbert/mbed_mem_trace_log_toggle

Add enable/disable cb function in mem_trace
pull/8272/head
Cruz Monrreal 2018-10-18 08:38:26 -05:00 committed by GitHub
commit ad6ada014a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -28,6 +28,7 @@
/* The callback function that will be called after a traced memory operations finishes. */ /* 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;
static mbed_mem_trace_cb_t mem_trace_cb_reserve;
/* 'trace_lock_count' guards "trace inside trace" situations (for example, the implementation /* '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 * 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. */ * 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; 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() void mbed_mem_trace_lock()
{ {
mem_trace_mutex->lock(); mem_trace_mutex->lock();

View File

@ -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); 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. * Trace lock.
* @note Locking prevent recursive tracing of malloc/free inside relloc/calloc * @note Locking prevent recursive tracing of malloc/free inside relloc/calloc