cpu/atmega_common: wrappers for memory management function to avoid preemption#11998
Merged
maribu merged 2 commits intoRIOT-OS:masterfrom Aug 13, 2019
Merged
Conversation
Memory management function like `malloc`, `calloc`, `realloc` and `free` must not be preempted when they operate on allocator structures. To avoid such a preemption, wrappers around these functions are used which simply disable all interrupts for the time of their execution.
14c8ded to
d84f75b
Compare
Contributor
|
is this related to #8619? |
Contributor
Author
|
Not really. PR #8619 implements the locking mechanism as used by |
Member
|
OK, for testing I modified Detailsdiff --git a/examples/hello-world/main.c b/examples/hello-world/main.c
index f51bf8c0a0..212e0f62f4 100644
--- a/examples/hello-world/main.c
+++ b/examples/hello-world/main.c
@@ -20,6 +20,7 @@
*/
#include <stdio.h>
+#include <stdlib.h>
int main(void)
{
@@ -27,6 +28,14 @@ int main(void)
printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
printf("This board features a(n) %s MCU.\n", RIOT_MCU);
+ void *a = malloc(4);
+ printf("void *a = %p\n", a);
+ void *b = calloc(4, 4);
+ printf("void *b = %p\n", b);
+ a = realloc(a, 32);
+ printf("void *a = %p (after realloc)\n", a);
+ free(a);
+ free(b);
return 0;
}The console output was DetailsSo no regressions were introduced. Finally, I disassembled the symbol main and got the following output: DetailsSo every call to |
maribu
approved these changes
Aug 13, 2019
Member
maribu
left a comment
There was a problem hiding this comment.
ACK. Thanks for this very elegant fix!
Contributor
Author
|
@maribu Thanks for reviewing, testing and merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
This PR is an aproach to fix the problem described in #10842.
Memory management function like
malloc,calloc,reallocandfreemust not be preempted when they operate on allocator structures. To avoid such a preemption, wrappers around these functions are used which simply disable all interrupts for the time of their execution.This approach produces 78 additional bytes of code.
Testing procedure
Flash and run
tests/malloc.Issues/PRs references
Fixes #10842