tls.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/tls.h
  3. // Purpose: wxTLS_TYPE()
  4. // Author: Vadim Zeitlin
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Macro to be used for thread-specific variables declarations.
  9. This macro can be used to define thread-specific variables of the specified
  10. @a type. Such variables must be global or static and must be POD, i.e.
  11. not have any constructors or destructor (even implicitly generated by the
  12. compiler due to use of base classes or members which are not POD in a
  13. struct).
  14. Example of use:
  15. @code
  16. struct PerThreadData
  17. {
  18. ... data which will be different for every thread ...
  19. };
  20. static wxTLS_TYPE(PerThreadData) s_threadDataVar;
  21. #define s_threadData (wxTLS_VALUE(s_threadDataVar))
  22. ... use s_threadData as a variable of type PerThreadData ...
  23. @endcode
  24. Notice that the use of the ugly wxTLS_VALUE() macro is unfortunately
  25. required if you need to support platforms without native compiler support
  26. for thread-specific variables. If you compile your code only on platforms
  27. which do have such support (recent versions of GNU C++ compiler, Microsoft
  28. Visual C++ and Sun C++ compiler are known to have it), you can avoid it and
  29. use the variable directly.
  30. */
  31. #define wxTLS_TYPE(type) compiler-dependent-implementation
  32. /**
  33. Macro to access thread-specific variables.
  34. This macro is used to hide the difference in implementation of
  35. thread-specific variables under different platforms: they can be of type T
  36. used in wxTLS_TYPE() if they are directly supported by the compiler or of
  37. type emulating @c T @c *, i.e. a pointer to this type otherwise. This macro
  38. always returns an expression of type @c T itself.
  39. As shown in wxTLS_TYPE() example, you may want to @c \#define a symbol
  40. wrapping a thread-specific variable with this macro. And, as also explained
  41. in wxTLS_TYPE() documentation, you may avoid using it entirely if you
  42. target only recent compilers.
  43. @see wxTLS_PTR()
  44. */
  45. #define wxTLS_VALUE(var)
  46. /**
  47. Macro to return address of a thread-specific variables.
  48. This macro is similar to wxTLS_VALUE() except that it always returns a
  49. pointer to the type of thread-specific variable.
  50. Notice that this is not a constant expression even if the macro is defined
  51. simply as @c &var -- the value returned is still different for every
  52. thread.
  53. */
  54. #define wxTLS_PTR(var)