1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/threadinfo.cpp
3 // Purpose: declaration of wxThreadSpecificInfo: thread-specific information
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2013 Vaclav Slavik <vslavik@fastmail.fm>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if defined(__BORLANDC__)
17 #include "wx/private/threadinfo.h"
22 #include "wx/thread.h"
23 #include "wx/sharedptr.h"
24 #include "wx/vector.h"
29 // All thread info objects are stored in a global list so that they are
30 // freed when global objects are destroyed and no memory leaks are reported.
32 // TODO: This could be made more efficient by freeing g_thisThreadInfo when
33 // wxThread terminates.
34 wxCriticalSection g_csAllThreadInfos
;
35 wxVector
< wxSharedPtr
<wxThreadSpecificInfo
> > g_allThreadInfos
;
37 // Pointer to currenct thread's instance
38 wxTLS_TYPE(wxThreadSpecificInfo
*) g_thisThreadInfo
;
40 } // anonymous namespace
43 wxThreadSpecificInfo
& wxThreadSpecificInfo::Get()
45 if ( !wxTLS_VALUE(g_thisThreadInfo
) )
47 wxTLS_VALUE(g_thisThreadInfo
) = new wxThreadSpecificInfo
;
48 wxCriticalSectionLocker
lock(g_csAllThreadInfos
);
49 g_allThreadInfos
.push_back(
50 wxSharedPtr
<wxThreadSpecificInfo
>(wxTLS_VALUE(g_thisThreadInfo
)));
52 return *wxTLS_VALUE(g_thisThreadInfo
);
55 #else // !wxUSE_THREADS
57 wxThreadSpecificInfo
& wxThreadSpecificInfo::Get()
59 static wxThreadSpecificInfo s_instance
;
63 #endif // wxUSE_THREADS/wxUSE_THREADS