Invalid rtems_id?

Joel Sherrill joel.sherrill at OARcorp.com
Thu Mar 27 15:01:18 UTC 2008


Chris Johns wrote:
> Joel Sherrill wrote:
>   
>> Sebastian Huber wrote:
>>     
>>> Hi,
>>> is there a standard way to test if a rtems_id is valid? I want to do the
>>> following:
>>>
>>> if (rtems_id == INVALID) {
>>>     use default object
>>> } else {
>>>     use object associated with rtems_id
>>> }
>>>
>>>       
>> Interesting question.
>>
>> Not at the moment as a direct answer.  There is a new collection
>> of object services if you look at the CVS head and the nightly
>> built documentation.  The rtems_object_get_name() would
>> be one way although heavy handed.
>>
>> If you want to define such as a service it sounds like a reasonable
>> addition to the Object Services methods.  The rtems_object_get_name()
>> code would be a good example.  It can take any id and has to know
>> if it is good or bad before grabbing the name.
>>
>> Be warned that there is officially no value that is an invalid id.
>> 0 is RTEMS_SELF which indicates the calling thread.  Technically
>> there are values which are always illegal (index portion == 0)
>> but we don't have an invalid id constant.
>>
>> This might be something worth discussing also.
>>     
>
> I came across this issue a number of years ago when implementing C++ wrappers
> and needed a way to see if an id was valid. I implemented 0xffffffff (sized to
> the correct id size) as the value. If this is pasted to RTEMS the operation
> will fail with an invalid id error code so I decided this was a suitable value.
>
> The theory is no part of the id matches a valid class so will alway fail.
>
> Is this worth making part of the formal API ?
>   
An invalid ID or an invalid ID check or both?

I would lean to both.

But I think that technically, I would say that an id with
0xffff0000 is more reliably invalid.  That would let us
max out the api, class, and node portions of the id
with an index of 0 which is never valid except in the
case of RTEMS_SELF which is 0x0.

But 0xffffffff says you are the max api and class which
means:

+ RTEMS has grown to 7 APIs, with 31 object classes
   in the highest numbered API
+ The object is from node 255 in an MP system. :-D
+ It is the 0xffff object of this type on that node.

So it is VERY unlikely to ever occur and not legal
now but within the technical definition of the
type long-term.

NOTE: There also has to be a 16-bit form of an
invalid ID.  If 0xffff0000 or 0xffffffff is OK for 32 bit
invalid ID, then 0xff00 or 0xffff is the 16-bit
equivalent.
> Regards
> Chris
>
>
>   


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985





More information about the users mailing list