_REENT

Artur Lipowski LAL@pro.onet.pl
Fri Jul 18 16:41:00 GMT 2008


Jeff Johnston wrote:
 > Raphael Derosso Pereira wrote:
 >> -----BEGIN PGP SIGNED MESSAGE-----
 >> Hash: SHA1
 >>
 >> I'm working with FreeRTOS and want to use _REENT, but I don't know how
 >> to setup this in a multithread environment. Is there any function that
 >> can be used to specify the current _REENT structure on context switch?
 >>
 >>
 > All that is needed is to set the global variable: _impure_ptr to a new 
reentrancy structure you have previously
 > initialized via the _REENT_INIT() macro.  See libc/reent/impure.c  You can do 
this manually in your
 > thread switching logic or you can do the following:
...

Try this (it works for me):

typedef struct tskTaskControlBlock
{
...
     #if ( configUSE_NEWLIB_REENTRANT == 1 )
         struct _reent reent;
     #endif
} tskTCB;


void vTaskSwitchContext( void )
{
...
     #if ( configUSE_NEWLIB_REENTRANT == 1 )
         _impure_ptr = &(pxCurrentTCB->reent);
     #endif

     traceTASK_SWITCHED_IN();
     vWriteTraceToBuffer();
}


static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed portCHAR * 
const pcName, unsigned portBASE_TYPE uxPriority )
{
...
     #if ( configUSE_NEWLIB_REENTRANT == 1 )
         _REENT_INIT_PTR((&(pxTCB->reent)));
     #endif
}


Regards,
-- 
Artur Lipowski



More information about the Newlib mailing list