Newlib reentrancy

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Apr 22 13:55:47 UTC 2013


On 04/22/2013 03:46 PM, Gedare Bloom wrote:
>>>> 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 ?
>> >
>> >
>> >No, but I haven't tested anything yet.
>> >
> Seems right to me. Do we need the check for NULL though, or can we
> define the invariant that _Thread_Executing->libc_reent is valid
> pointer to the reent structure?
>

I want to avoid the every program needs a reference to the global reentrancy 
structure.  We have the configuration option 
CONFIGURE_DISABLE_NEWLIB_REENTRANCY.  In case this option is defined, then we 
should initialize thread->libc_reent to NULL.  If we initialize it to 
_global_impure_ptr, then we pull in the global reentrancy structure even if we 
don't need it in the application.  If someone needs it, then he gets the 
reference via __getreent().

Now I think that an even better approach is to define __getreent() in 
confdefs.h depending on CONFIGURE_DISABLE_NEWLIB_REENTRANCY, e.g.

struct _reent *__getreent(void)
{
#ifdef CONFIGURE_DISABLE_NEWLIB_REENTRANCY
   return _global_impure_ptr;
#else
   return _Thread_Executing->libc_reent;
#endif
}

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the devel mailing list