[wx-dev] wxThread, thread local storage and wxLog

Armel Asselin asselin.armel at wanadoo.fr
Fri Aug 11 03:39:54 PDT 2006


> AA> this wxThreadData structure which from your description would be 
> something
> AA> like:
> AA>
> AA> srtuct wxThreadData {
> AA>     wxThread *wxThread_This;
> AA>
> AA>     bool  wxLog_ActiveTarget;
> AA> };
>
> This is the simplest possibility. Another one to have a map with strings
> as keys and wxVariants as values.
(note: it would be a second level of tls in fact, but awfully inefficient)

what I proposed with the vocable "one system tls entry + array" is that, i 
was not clear probably:
- have a wxThreadSpecificDataHolder, it handles a single entry in the system 
TLS. In this entry it stores a pointer to an instance of itself. This 
instance contains an array of pointers. The class itself contains a static 
member array telling which slots are still used in the TLS and for each used 
slot which destructor function to call (this array is protected with a 
mutex). This class handles platform-specific sutff through a 'impl' member.
- a static member of wxThreadSpecificDataHolder (::Cleanup) is called when a 
thread exits (wxThread::Exit), and/or in DllMain DLL_THREAD_DETACH for 
example on Windows
- have a wxThreadSpecificData, it works by calling 
wxThreadSpecificDataHolder::AllocSlot (destructor_func=NULL) in its 
constructor, FreeSlot in the destructor, the Get and Set functions are as 
usual.

the advantages:
- we are both ok: one tls entry, but this time for _all_ stuff, including wx 
developper/users tls related stuff
- no common struct and as such, no additional header to maintain
- just one more indirection to get access to an object

Armel





More information about the wx-dev mailing list