This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ID for cyg_thread_get_info


Billy <billy@DaDaDaDa.net> writes:

> How do I get an ID to use in cyg_thread_get_info()?
> I want a write routine to get the thread name.
> 
> Do I really have to go into a cyg_thread_get_next() loop
> enumerating all of the threads until I match the handle
> obtained with cyg_thread_self()?  That seems to be the
> only way of getting the kernel to cough up a thread id.
> 
> Do I really have to do all of this work in my id_for_thread()?
> 
>     cyg_uint16
>     id_for_thread(cyg_handle_t needle)
>     {
> 	cyg_uint16 id = 0;
> 	cyg_handle_t *haystack = 0;
>         while( cyg_thread_get_next(&haystack, &id) )
> 	    if(haystack == needle)
> 		return id;
> 	return 0;
>     }
> 
>     char *
>     thread_name(char *buf)
>     {
>         cyg_thread_info info;
> 	cyg_handle_t myself = cyg_thread_self();
>         cyg_uint16 id = id_for_thread(myself);
>         cyg_thread_get_info(myself, id, &info);
>         return strcpy(buf, info->name);
>     }
> 
> Why does cyg_thread_get_info() need the id parameter at all?
> Is there a reason that it can't just use the id associated with
> the handle which was already given as argument 1?
> 

That API was really invented to support code that needed to enumerate
all the threads in the system. Needing to supply both the handle and
the id allows us to detect cases where the thread has been deleted and
the memory reused between calls to cyg_thread_get_next().

So at present, yes, you do have to trawl through all the threads to do
this. Although you could cheat and cast the handle to a cyg_thread
object and pull the id out of that. However, we don't guarantee that
the fields will always match up correctly, so this is only a short
term solution.

I suspect that a cyg_thread_get_id() function might be useful. I'll
look at adding it.

-- 
Nick Garnett                    eCos Kernel Architect
http://www.ecoscentric.com/     The eCos and RedBoot experts


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]