Commit af5d44c6 by Reed Kotler Committed by Jim Stichnoth

Do some small cleanup in IceTLS.h and add some markup for doxygen to it.

BUG= R=jpp@chromium.org, stichnot@chromium.org Review URL: https://codereview.chromium.org/1430273004 . Patch from Reed Kotler <rkotlerimgtec@gmail.com>.
parent f5f02f7e
...@@ -17,37 +17,41 @@ ...@@ -17,37 +17,41 @@
#ifndef SUBZERO_SRC_ICETLS_H #ifndef SUBZERO_SRC_ICETLS_H
#define SUBZERO_SRC_ICETLS_H #define SUBZERO_SRC_ICETLS_H
#if defined(_MSC_VER)
#define ICE_ATTRIBUTE_TLS __declspec(thread)
#else // !_MSC_VER
#define ICE_ATTRIBUTE_TLS thread_local
#endif // !_MSC_VER
// Defines 4 macros for unifying thread_local and pthread: ///
// /// @defgroup /IceTLS Defines 5 macros for unifying thread_local and pthread:
// ICE_TLS_DECLARE_FIELD(Type, FieldName): Declare a static thread_local field /// @{
// inside the current class definition. "Type" needs to be a pointer type, such ///
// as int* or class Foo*. /// \def ICE_TLS_DECLARE_FIELD(Type, FieldName)
// /// Declare a static thread_local field inside the current class definition.
// ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName): Define a static /// "Type" needs to be a pointer type, such as int* or class Foo*.
// thread_local field outside of its class definition. The field will ///
// ultimately be initialized to nullptr. /// \def ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName)
// /// Define a static thread_local field outside of its class definition. The
// ICE_TLS_INIT_FIELD(FieldName): Ensure the thread_local field is properly /// field will ultimately be initialized to nullptr.
// initialized. This is intended to be called from within a static method of ///
// the field's class after main() starts (to ensure that the pthread library is /// \def ICE_TLS_INIT_FIELD(FieldName)
// fully initialized) but before any uses of ICE_TLS_GET_FIELD or /// Ensure the thread_local field is properly initialized. This is intended
// ICE_TLS_SET_FIELD. /// to be called from within a static method of the field's class after main()
// /// starts (to ensure that the pthread library is fully initialized) but before
// ICE_TLS_GET_FIELD(Type, FieldName): Read the value of the static /// any uses of ICE_TLS_GET_FIELD or ICE_TLS_SET_FIELD.
// thread_local field. Must be done within the context of its class. ///
// /// \def ICE_TLS_GET_FIELD(Type, FieldName)
// ICE_TLS_SET_FIELD(FieldName, Value): Write a value into the static /// Read the value of the static thread_local field. Must be done within the
// thread_local field. Must be done within the context of its class. /// context of its class.
///
/// \def ICE_TLS_SET_FIELD(FieldName, Value)
/// Write a value into the static thread_local field. Must be done within the
/// context of its class.
/// \todo TODO(stichnot)
/// Limit this define to only the platforms that absolutely require it. And
/// ideally, eventually remove this hack altogether.
///
// TODO(stichnot): Limit this define to only the platforms that ///
// absolutely require it. And ideally, eventually remove this hack /// \def ICE_THREAD_LOCAL_HACK
// altogether. ///
#define ICE_THREAD_LOCAL_HACK #define ICE_THREAD_LOCAL_HACK
#ifdef ICE_THREAD_LOCAL_HACK #ifdef ICE_THREAD_LOCAL_HACK
...@@ -86,6 +90,13 @@ ...@@ -86,6 +90,13 @@
#else // !ICE_THREAD_LOCAL_HACK #else // !ICE_THREAD_LOCAL_HACK
#if defined(_MSC_VER)
#define ICE_ATTRIBUTE_TLS __declspec(thread)
#else // !_MSC_VER
#define ICE_ATTRIBUTE_TLS thread_local
#endif // !_MSC_VER
#define ICE_TLS_DECLARE_FIELD(Type, FieldName) \ #define ICE_TLS_DECLARE_FIELD(Type, FieldName) \
static ICE_ATTRIBUTE_TLS Type FieldName static ICE_ATTRIBUTE_TLS Type FieldName
#define ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName) \ #define ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName) \
...@@ -96,4 +107,8 @@ ...@@ -96,4 +107,8 @@
#endif // !ICE_THREAD_LOCAL_HACK #endif // !ICE_THREAD_LOCAL_HACK
///
/// @}
///
#endif // SUBZERO_SRC_ICETLS_H #endif // SUBZERO_SRC_ICETLS_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment