I want to port the newlib malloc function to FreeRTOS. To ensure that the malloc functions are thread-safe, following function should be provided:
following hint is inside the newlib documentation:
A call to <<malloc>> may call <<__malloc_lock>> recursively; that is,
the sequence of calls may go <<__malloc_lock>>, <<__malloc_lock>>,
<<__malloc_unlock>>, <<__malloc_unlock>>. Any implementation of these
routines must be careful to avoid causing a thread to wait for a lock
that it already holds.
To avoid locking out themself, i need an information which task is currently executed. Is there an easy way to implement a function like GetCurrentTCB()?
If different threads works in the library at the same time, it can creates reentrancy problems. Newlib avoid this with the _impure_ptr to a _reent struct. Every task should have his own _reent structure and the _impure_ptr is moving between these structures during context switches.
How can i implement this? Is it possible to implement a callback function inside the scheduler?