43b8002b14
This commit adds the newlib retargetable locking interface function implementations in order to make newlib functions thread safe. The newlib retargetable locking interface is internally called by the standard C library functions provided by newlib to synchronise access to the internal shared resources. By default, the retargetable locking interface functions defined within the newlib library are no-op. When multi-threading is enabled (i.e. `CONFIG_MULTITHREADING=y`), the Zephyr-side retargetable locking interface implementations override the default newlib implementation and provide locking mechanism. The retargetable locking interface may be called with either a static (`__lock__...`) or a dynamic lock. The static locks are statically allocated and initialised immediately after kernel initialisation by `newlib_locks_prepare`. The dynamic locks are allocated and de-allocated through the `__retargetable_lock_init[_recursive]` and `__retarget_lock_close_[recurisve]` functions as necessary by the newlib functions. These locks are allocated in the newlib heap using the `malloc` function when userspace is not enabled -- this is safe because the internal multi-threaded malloc lock implementations (`__malloc_lock` and `__malloc_unlock`) call the retargetable locking interface with a static lock (`__lock__malloc_recursive_mutex`). When userspace is enabled, the dynamic locks are allocated and freed through `k_object_alloc` and `k_object_release`. Note that the lock implementations used here are `k_mutex` and `k_sem` instead of `sys_mutex` and `sys_sem` because the Zephyr kernel does not currently support dynamic allocation of the latter. These locks should be updated to use `sys_mutex` and `sys_sem` when the Zephyr becomes capable of dynamically allocating them in the future. Signed-off-by: Stephanos Ioannidis <root@stephanos.io> |
||
---|---|---|
.. | ||
minimal | ||
newlib | ||
CMakeLists.txt | ||
Kconfig |