[En-Nut-Discussion] Thread private date
Ernst Stippl
ernst at stippl.org
Tue Feb 26 20:10:14 CET 2008
Hi Ole!
I seem to be a bit slow today, but why is such a pointer "more" thread-
privat than a pointer just declared within the thread?
One more question: Why will it "break existing applications" when the size
of a Nut/OS internal data structure changes? I would think that, if the
application is coded up to generally accepted standards, it will determine
the size of the structure's element and thus being able to "run" thru the
list.
Another one: I have seen extensions of operating system structures by adding
a second structure holding the "new" information. Like a process control
block (PCB) and a process control block-extension (PCBX). The PCB was left
unchanged and the PCBX was used to store the additional information. At the
same time an API was provided to help walk up and down the PCBX list to help
ensure applications use this API to access the new structure and at the same
time make sure the documentation contains highly visible remarks that direct
access to this structure is *very* bad programming and may break code.
(Which should be clear, anyway).
Regards
Ernst
-----Ursprüngliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] Im Auftrag von Ole Reinhardt
Gesendet: Dienstag, 26. Februar 2008 17:51
An: Ethernut User Chat (English)
Betreff: [En-Nut-Discussion] Thread private date
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 |
|_____________________________________________________________|
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.21.0/1296 - Release Date: 24.02.2008
12:19
More information about the En-Nut-Discussion
mailing list