Newlib reentrancy

Chris Johns chrisj at rtems.org
Mon Apr 22 10:09:18 UTC 2013


Sebastian Huber wrote:
> Hello,
>
> Newlib stores all global state in a so called reentrancy structure, e.g.
> errno, stdin, random number state, etc. In RTEMS every thread can have
> its own reentrancy structure (a reference it is part of the thread
> control block). In Newlib there are two mechanisms to access the
> executing thread's reentrancy structure
>
> 1. via a global pointer _impure_ptr, or
> 2. via a function __getreent().
>
> See also:
>
> http://sourceware.org/ml/newlib/2013/msg00031.html
>
> Currently RTEMS uses option 1. The global pointer is updated during a
> thread dispatch in threaddispatch.c.
>
> The option 1. is unsuitable for SMP since here a global pointer cannot
> be used to store thread specific data. I suggest to use option 2. for
> RTEMS.

I agree. What is needed to define this support when building newlib ?

> For the single-processor RTEMS this has the benefit that the
> thread dispatch code is simplified, e.g. the code block
>
> /*
> * Switch libc's task specific data.
> */
> if ( _Thread_libc_reent ) {
> executing->libc_reent = *_Thread_libc_reent;
> *_Thread_libc_reent = heir->libc_reent;
> }
>
> can be removed. The execution time of _Thread_Dispatch() is critical for
> the interrupt and thread switch latency.
>
> The implementation of __getreent() for RTEMS is easy:
>
> struct _reent *__getreent(void)
> {
> struct _reent *reent = _Thread_Executing->libc_reent;
>
> if ( reent == NULL ) {
> reent = _global_impure_ptr;
> }
>
> return reent;
> }

Does this code need locking ?

Chris



More information about the devel mailing list