Thread safe memory allocation

parmi wrote on Monday, August 19, 2019:

I tried to define the malloc_lock and malloc_unlock functions, but the linker gives me an error.

main.cpp

extern "C" void __malloc_lock(struct _reent *REENT)
{
	vPortEnterCritical();
}

extern "C" void __malloc_unlock(struct _reent *REENT)
{
	vPortExitCritical();
}

Linking error:

1>Linking ../MyProject/...
1>c:/sysgcc/arm-eabi/bin/../lib/gcc/arm-eabi/7.2.0/../../../../arm-eabi/lib/thumb/cortex_m4\libc_nano.a(lib_a-mlock.o): In function `__malloc_lock':
1>q:\gnu\newlib-nano\gcc-arm-none-eabi-6-2017-q2-update\src\newlib\newlib\libc\stdlib\mlock.c(53): error : multiple definition of `__malloc_lock'
1>VisualGDB/Debug/main.o:C:\visual_gdb_workspace\MyProject\MyProject/main.cpp:130: first defined here
1>collect2.exe : error : ld returned 1 exit status