-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add enable/disable cb function in mem_trace #7948
Conversation
platform/mbed_mem_trace.cpp
Outdated
@@ -45,6 +46,18 @@ void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb) { | |||
mem_trace_cb = cb; | |||
} | |||
|
|||
void mbed_mem_trace_disable() | |||
{ | |||
mem_trace_cb_reserve = mem_trace_cb; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it be interesting to check it in multi threaded system, when some thread trying to activate it and other disable it. I am not sure if that is a valid use case or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deepikabhavnani Good point! Updated it by adding the mutex locks used around malloc calls in the enable/disable functions. Do you think that'd be sufficient? Writing up a quick test in the meantime. Will squash the commits later if it works out fine.
There still could be the concern with someone using different callbacks in different threads while enabling/disabling logging output as two subsequent disables would wipe out the first cb state. Added a change to check for the current cb pointer to see if it was already null and not to disable twice. This would cause the second disable to lose its state however. Wanted to allow an internal storage mechanism for the original cb to prevent needing to have the user maintain the pointer and pass it around between threads potentially but this does add some complexity to corner cases like this. |
I'll also add a check on the currently set cb to ensure it's null before overwriting it with the reserve to stop the following:
|
23a2d66
to
29e7676
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
/morph build |
Build : SUCCESSBuild number : 3220 Triggering tests/morph test |
Test : FAILUREBuild number : 3023 |
/morph test |
1 similar comment
/morph test |
Test : SUCCESSBuild number : 3072 |
/morph export-build |
Exporter Build : SUCCESSBuild number : 2888 |
platform/mbed_mem_trace.cpp
Outdated
void mbed_mem_trace_enable() | ||
{ | ||
mbed_mem_trace_lock(); | ||
if (mem_trace_cb == 0 && mem_trace_cb_reserve) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'If (mem_trace_cb == 0)' this is inconsistent with the previous function where 'if (mem_trace_cb)' is used. One is checking a value directly and one is treating the variable as a logical True/False (which I assume is how it should be used). If the latter is indeed true then the checking against 0 should actually be replaced by:
if (!mem_trace_cb).
@kegilbert please address comment. |
29e7676
to
eeada14
Compare
@adbridge Updated |
Note: This could probably come into 10.2. |
enhancement - new functionality thus 5.11 is good here. |
/morph build |
Build : SUCCESSBuild number : 3393 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 3024 |
Test : SUCCESSBuild number : 3194 |
Description
This came up in: #7888
This adds a slightly cleaner method to enabling/disabling the memory tracing callbacks as outlined the above issue.
Tested with:
@deepikabhavnani
Pull request type