-
Notifications
You must be signed in to change notification settings - Fork 683
Allow the port to allocate/deallocate the heap #946
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* Copyright 2014 Samsung Electronics Co., Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef MEM_HEAP_INTERNAL_H | ||
#define MEM_HEAP_INTERNAL_H | ||
|
||
#ifndef MEM_HEAP_INTERNAL | ||
# error "The header is for internal routines of memory heap component. Please, don't use the routines directly." | ||
#endif /* !MEM_HEAP_INTERNAL */ | ||
|
||
#include "mem-allocator.h" | ||
#include "mem-config.h" | ||
|
||
/** \addtogroup mem Memory allocation | ||
* @{ | ||
*/ | ||
|
||
/* Calculate heap area size, leaving space for a pointer to the free list */ | ||
#define MEM_HEAP_AREA_SIZE (MEM_HEAP_SIZE - MEM_ALIGNMENT) | ||
#define MEM_HEAP_END_OF_LIST ((mem_heap_free_t *const) ~((uint32_t) 0x0)) | ||
|
||
/** | ||
* Free region node | ||
*/ | ||
typedef struct | ||
{ | ||
uint32_t next_offset; /* Offset of next region in list */ | ||
uint32_t size; /* Size of region */ | ||
} mem_heap_free_t; | ||
|
||
#ifdef MEM_HEAP_PTR_64 | ||
#define MEM_HEAP_GET_OFFSET_FROM_ADDR(h, p) ((uint32_t) ((uint8_t *) (p) - (uint8_t *) (h)->area)) | ||
#define MEM_HEAP_GET_ADDR_FROM_OFFSET(h, u) ((mem_heap_free_t *) &(h)->area[u]) | ||
#else | ||
/* In this case we simply store the pointer, since it fits anyway. */ | ||
#define MEM_HEAP_GET_OFFSET_FROM_ADDR(h, p) ((uint32_t) (p)) | ||
#define MEM_HEAP_GET_ADDR_FROM_OFFSET(h, u) ((mem_heap_free_t *)(u)) | ||
#endif | ||
|
||
/** | ||
* Heap structure | ||
*/ | ||
struct mem_heap | ||
{ | ||
mem_heap_free_t first; | ||
/* This is used to speed up deallocation. */ | ||
mem_heap_free_t *list_skip_p; | ||
/** | ||
* Size of allocated regions | ||
*/ | ||
size_t allocated_size; | ||
|
||
/** | ||
* Current limit of heap usage, that is upon being reached, causes call of "try give memory back" callbacks | ||
*/ | ||
size_t limit; | ||
|
||
/** | ||
* Heap area | ||
*/ | ||
uint8_t area[MEM_HEAP_AREA_SIZE] __attribute__ ((aligned (MEM_ALIGNMENT))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't that simple. The allocator should ensure the alignment. I would only put this member into a dynamic struct. |
||
}; | ||
|
||
|
||
/** | ||
* @} | ||
*/ | ||
|
||
#endif /* MEM_HEAP_INTERNAL_H */ |
Oops, something went wrong.
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.
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.
I think we should add a size argument to this function. At least the implementation can check the size.
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.
ok!