[En-Nut-Discussion] Thread private date

Ole Reinhardt ole.reinhardt at embedded-it.de
Tue Feb 26 17:51:02 CET 2008


Hi all,

I just had an Idea for a simple but quite versatile improvement to
NutOs's threads.

It could be very usefull to have some thread private data pointer that
could be obtained by calling e.G. NutThreadGetPrivate() /
NutThreadSetPrivate().

This feature could be easily implemented by adding a new pointer to the
NUTTHREADINFO struct.

Ok, you all shout: This will break existing applications.

Next Idea:

When creating a thread, the threads stack is allocated and filled with
four "0xdeadbeef" at the bottom.

If we now first add four bytes holding our private data pointer, we do
not need to alter any existing code but could acess this pointer at
runtime like this:

void NutSetPrivate(uptr_t user_data)
{
    memcpy(runningThread->td_memory, &user_data, sizeof(uptr_t));
}

uptr_t NutGetPrivate(void)
{
    uptr_t user_data;
    memcpy(&user_data, runningThread->td_memory, sizeof(uptr_t));
    return user_data;
}

That's just a small hack but could be quite usefull!

Any comments and suggestions are wellcome!

Bye,

Ole Reinhardt


-- 
 _____________________________________________________________
|                                                             |
| Embedded-IT          Hard- und Softwarelösungen             |
|                                                             |
| Ole Reinhardt        Tel. / Fax:        +49 (0)271  7420433 |
| Luisenstraße 29      Mobil:             +49 (0)177  7420433 |
| 57076 Siegen         eMail:    ole.reinhardt at embedded-it.de |
| Germany              Web:         http://www.embedded-it.de |
|                      UstID / VAT:       DE198944716         |
|_____________________________________________________________|




More information about the En-Nut-Discussion mailing list