malloc, threadsafety and others
Posted: Thu May 24, 2012 12:55 pm
Hi,
I am new to ChibiOS and got a few questions.
I got a demo for ARMCM3-STM32F103 (OLIMEX Board) up and running.
Background:
I know that there are several allocators and i know that _sbrk_r() is provided in os/various/syscalls.c and that it uses the ChibiCoreAllocator.
Given:
WINDOWS
GNU Tools for ARM Embedded: https://launchpad.net/gcc-arm-embedded (using redhat libc)
GNU make und GNU fileutils/coreutils (primary for rm -rf): http://gnuwin32.sourceforge.net/
1.
When I use malloc (because i want to use a clib-function which uses malloc, there are a lot of them) is this threadsafe?
malloc uses the given _sbrk_r(), which is threadsafe, but is malloc itself threadsafe?
There are malloc_lock(), malloc_unlock() stubs, which can be filled to e.g. lock the scheduler (chSysLock(), chSysUnlock()), but this doesn't seem right.
How do i overwrite the clib-malloc()-funtions with threadsafe chHeadAlloc() and friends?
2.
Does g++ new() use the same clib-malloc()-functions?
If not, how to overwrite with threadsafe ChibiOS ones?
3.
Many clib- and mlib-functions are not threadsafe (global errno e.g.).
From what I see I need to add an "struct _reent" structure of the clib to the THEAD_EXT_FILEDS, Initialize it in THREAD_EXT_INIT_HOCK with _REENT_INIT_PTR and set the _impure_ptr every task switch in THREAD_CONTEXT_SWITCH_HOOK?
I searched thru close to all documentation and found nothing.
Thanks.
PS: I got some background with FreeRTOS, but wanted more.
I am new to ChibiOS and got a few questions.
I got a demo for ARMCM3-STM32F103 (OLIMEX Board) up and running.
Background:
I know that there are several allocators and i know that _sbrk_r() is provided in os/various/syscalls.c and that it uses the ChibiCoreAllocator.
Given:
WINDOWS
GNU Tools for ARM Embedded: https://launchpad.net/gcc-arm-embedded (using redhat libc)
GNU make und GNU fileutils/coreutils (primary for rm -rf): http://gnuwin32.sourceforge.net/
1.
When I use malloc (because i want to use a clib-function which uses malloc, there are a lot of them) is this threadsafe?
malloc uses the given _sbrk_r(), which is threadsafe, but is malloc itself threadsafe?
There are malloc_lock(), malloc_unlock() stubs, which can be filled to e.g. lock the scheduler (chSysLock(), chSysUnlock()), but this doesn't seem right.
How do i overwrite the clib-malloc()-funtions with threadsafe chHeadAlloc() and friends?
2.
Does g++ new() use the same clib-malloc()-functions?
If not, how to overwrite with threadsafe ChibiOS ones?
3.
Many clib- and mlib-functions are not threadsafe (global errno e.g.).
From what I see I need to add an "struct _reent" structure of the clib to the THEAD_EXT_FILEDS, Initialize it in THREAD_EXT_INIT_HOCK with _REENT_INIT_PTR and set the _impure_ptr every task switch in THREAD_CONTEXT_SWITCH_HOOK?
I searched thru close to all documentation and found nothing.
Thanks.
PS: I got some background with FreeRTOS, but wanted more.