a question about RTEMS notepad

Eric Norum norume at aps.anl.gov
Wed Apr 11 20:39:21 UTC 2007


On Apr 11, 2007, at 2:18 PM, Till Straumann wrote:

> IMHO, since the notepads are zeroed
> at task creation (earlier versions of
> RTEMS left them undefined) they have
> become really useful as 'light-weight' task
> variables. Plus, their 'affiliation'
> with a task context is more obvious
> than in the case of a task variable.

Yes, and in fact that's exactly how RTEMS provides for EPICS  
'operating system dependent'  thread private variables.  A single  
notepad entry is used to refer to a structure containing all the  
information associated with a thread:

void epicsThreadPrivateSet (epicsThreadPrivateId id, void *pvt)
{
     unsigned int varIndex = (unsigned int)id;
     rtems_unsigned32 note;
     struct taskVar *v;
     int i;

     rtems_task_get_note (RTEMS_SELF, RTEMS_NOTEPAD_TASKVAR, &note);
     v = (struct taskVar *)note;
     if (varIndex >= v->threadVariableCapacity) {
         v->threadVariables = realloc (v->threadVariables, (varIndex  
+ 1) * sizeof (void *));
         if (v->threadVariables == NULL)
             cantProceed("epicsThreadPrivateSet realloc failed\n");
         for (i = v->threadVariableCapacity ; i < varIndex ; i++)
             v->threadVariables[i] = NULL;
         v->threadVariableCapacity = varIndex + 1;
     }
     v->threadVariables[varIndex] = pvt;
}

void * epicsThreadPrivateGet (epicsThreadPrivateId id)
{
     unsigned int varIndex = (unsigned int)id;
     rtems_unsigned32 note;
     struct taskVar *v;

     rtems_task_get_note (RTEMS_SELF, RTEMS_NOTEPAD_TASKVAR, &note);
     v = (struct taskVar *)note;
     if (varIndex >= v->threadVariableCapacity)
         return NULL;
     return v->threadVariables[varIndex];
}


-- 
Eric Norum <norume at aps.anl.gov>
Advanced Photon Source
Argonne National Laboratory
(630) 252-4793





More information about the users mailing list