threadinfo.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/private/threadinfo.h
  3. // Purpose: declaration of wxThreadSpecificInfo: thread-specific information
  4. // Author: Vadim Zeitlin
  5. // Created: 2009-07-13
  6. // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_PRIVATE_THREADINFO_H_
  10. #define _WX_PRIVATE_THREADINFO_H_
  11. #include "wx/defs.h"
  12. class WXDLLIMPEXP_FWD_BASE wxLog;
  13. #if wxUSE_INTL
  14. #include "wx/hashset.h"
  15. WX_DECLARE_HASH_SET(wxString, wxStringHash, wxStringEqual,
  16. wxLocaleUntranslatedStrings);
  17. #endif
  18. // ----------------------------------------------------------------------------
  19. // wxThreadSpecificInfo: contains all thread-specific information used by wx
  20. // ----------------------------------------------------------------------------
  21. // Group all thread-specific information we use (e.g. the active wxLog target)
  22. // a in this class to avoid consuming more TLS slots than necessary as there is
  23. // only a limited number of them.
  24. class wxThreadSpecificInfo
  25. {
  26. public:
  27. // Return this thread's instance.
  28. static wxThreadSpecificInfo& Get();
  29. // the thread-specific logger or NULL if the thread is using the global one
  30. // (this is not used for the main thread which always uses the global
  31. // logger)
  32. wxLog *logger;
  33. // true if logging is currently disabled for this thread (this is also not
  34. // used for the main thread which uses wxLog::ms_doLog)
  35. //
  36. // NB: we use a counter-intuitive "disabled" flag instead of "enabled" one
  37. // because the default, for 0-initialized struct, should be to enable
  38. // logging
  39. bool loggingDisabled;
  40. #if wxUSE_INTL
  41. // Storage for wxTranslations::GetUntranslatedString()
  42. wxLocaleUntranslatedStrings untranslatedStrings;
  43. #endif
  44. #if wxUSE_THREADS
  45. // Cleans up storage for the current thread. Should be called when a thread
  46. // is being destroyed. If it's not called, the only bad thing that happens
  47. // is that the memory is deallocated later, on process termination.
  48. static void ThreadCleanUp();
  49. #endif
  50. private:
  51. wxThreadSpecificInfo() : logger(NULL), loggingDisabled(false) {}
  52. };
  53. #define wxThreadInfo wxThreadSpecificInfo::Get()
  54. #endif // _WX_PRIVATE_THREADINFO_H_