- MCU: nRF52840
- IDE: Keil uVision 5.17
- SDK: 15.2.0
- Board: Custom
- OS: FreeRTOS
- Using MicroLIB
Hello,
I am currently working on a FreeRTOS project that leverages a third party data processing library that internally uses malloc(), realloc(), and free(). I realize that all of these malloc() and associated calls should ideally be replaced with FreeRTOS equivalents pvPortMalloc(), vPortFree(), and a custom solution for realloc(). However, I am fine with allowing this library to use the standard heap as defined by '__HEAP_SIZE=8092' in my preprocessor symbols. My concern is whether or not the malloc() standard library functions are thread safe in MicroLIB.
According to the ARM documentation, it doesn't state MicroLIB specifically, but it does state that malloc() and other standard functions can be made thread safe by specifying _mutex_* functions.
Question 1: Is malloc(), free(), and realloc() thread safe in MicroLib? I am not sure whether the link above applies to the default C library or MicroLIB.
Question 2: If not thread safe, does anyone have the correct function prototypes for the necessary mutex functions in MicroLib? The only thing I have been able to find is the following from an unofficial source:
int _mutex_initialize (OS_ID *mutex) __attribute__((used)); void _mutex_acquire (OS_ID *mutex) __attribute__((used)); void _mutex_release (OS_ID *mutex) __attribute__((used));
Lastly, I tested compiling my code with the "MicroLIB" box not checked, and I can now see the following in my .map file:
_mutex_acquire - Undefined Weak Reference
_mutex_free - Undefined Weak Reference
_mutex_release - Undefined Weak Reference
So it seems the standard library has some sort of existing implementation that I have no visibility into.
Thanks,
Derek