Reentrancy in newlib functions
Posted: Thu Sep 22, 2011 11:10 pm
My program currently makes use of some of the printf-like functions from multiple threads. Reading the newlib docs indicates that I need to set the global variable "_impure_ptr" to a "struct _reent" variable for the specific thread. Other Internet searches indicate I can define __DYNAMIC_REENT__ which will cause newlib to call a function __getreent() that I can implement to get the current thread's structure.
If I go the dynamic route, I figure I can just return a pointer based on a static thread-id (since I don't use dynamic threads, and not all of my threads use these functions). The other option would be to modify THREAD_EXT_FIELDS to do something similar.
Does this sound like I'm on the right path, or is there an example or "best practice" to ensure reentrancy in the newlib functions from ChibiOS?
I'm using CodeSourcery Lite 2010q1-188 and STM32 with my project.
Thanks,
Brian
If I go the dynamic route, I figure I can just return a pointer based on a static thread-id (since I don't use dynamic threads, and not all of my threads use these functions). The other option would be to modify THREAD_EXT_FIELDS to do something similar.
Does this sound like I'm on the right path, or is there an example or "best practice" to ensure reentrancy in the newlib functions from ChibiOS?
I'm using CodeSourcery Lite 2010q1-188 and STM32 with my project.
Thanks,
Brian