Feat/TLSFAlloc#105
Conversation
Pistonight
left a comment
There was a problem hiding this comment.
Licesne file(s) need to be updated
| @@ -5,25 +5,3 @@ | |||
|
|
|||
| #include <switch/types.h> | |||
There was a problem hiding this comment.
do we still need this header if it's just a single define?
| #include <nn/os/os_Mutex.h> | ||
|
|
||
| namespace nn::os { | ||
| Mutex::~Mutex() { |
There was a problem hiding this comment.
Why does this need to be implemented?
| void *ptr = allocator().Allocate(size, align); | ||
| if (ptr != nullptr) { | ||
| return (u8 *)ptr; | ||
| mem_mutex.Lock(); |
There was a problem hiding this comment.
Why are we not unlocking? consider making a Scope lock wrapper
| return (u8 *)ptr; | ||
| mem_mutex.Lock(); | ||
| if (!mem_initialized) { | ||
| allocator = tlsf_create_with_pool(bss_alloc, BSS_ALLOC_SIZE); |
There was a problem hiding this comment.
I think it will be slightly simpler to initialize the pool as part of the lib init then you don't need to track if it's initialized
There was a problem hiding this comment.
static-initialized memory in rust can't allocate so this will not get called before initialization
| StandardAllocator(); | ||
| StandardAllocator(void* address, size_t size); | ||
| StandardAllocator(void* address, size_t size, bool enableCache); | ||
| #include <megaton/__internal/tlsf.h> |
There was a problem hiding this comment.
it's best to not expose tlsf.h, which is implementation detail
There was a problem hiding this comment.
This is exposed so that allocator can be initialized in init.cpp (without it the type pool_t and the function tlsf_create_with_pool are undefined). Is there a better approach to achieving this? I thought the header was appropriate because BSS_ALLOC_SIZE should only be defined in one place.
There was a problem hiding this comment.
// __internal/alloc.h
namespace megaton::alloc {
void init_pool();
}
// alloc.cpp
static YOUR_GLOBAL_VARIABLES_HERE;
namespace megaton::alloc {
void init_pool() {
allocator = tlsf_create_with_pool(..);
}
}
// init.cpp
void __megaton_librs_init() {
megaton::alloc::init_pool();
}If you imagine alloc.cpp and init.cpp as 2 classes, allocator is like a private field that should not be exposed, but it can be initialized via a public interface (a function)
|
|
||
| void __megaton_librs_init() { | ||
| allocator = tlsf_create_with_pool(bss_alloc, BSS_ALLOC_SIZE); | ||
| return; |
There was a problem hiding this comment.
You can declare a megaton::alloc::init_pool in alloc.h then implementation detail will not be exposed (i.e. you don't need tlsf.h here or any of the extern symbols)
|
|
||
| void Mutex::unlock() { | ||
| this->Unlock(); | ||
| } |
There was a problem hiding this comment.
Why does these need to be implemented? they should already be defined in the SDK
Pistonight
left a comment
There was a problem hiding this comment.
The nn::os::Mutex implementation should be removed, you should only need the header
|
I take no issue with removing the nn::os::Mutex, but it was added as a result of an undefined symbol error we had encountered previously, specifically |
|
Additionally, should the |
|
Ok I remember the dtor issue.. maybe try using std::mutex? |
Integration of TLSF allocator