Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(907)

Side by Side Diff: src/IceTLS.h

Issue 1430273004: Do some small cleanup in IceTLS.h and add some markup for doxygen (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceTLS.h - thread_local workaround -----------*- C++ -*-===// 1 //===- subzero/src/IceTLS.h - thread_local workaround -----------*- C++ -*-===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
11 /// This file defines macros for working around the lack of support for 11 /// This file defines macros for working around the lack of support for
12 /// thread_local in MacOS 10.6. It assumes std::thread is written in terms of 12 /// thread_local in MacOS 10.6. It assumes std::thread is written in terms of
13 /// pthread. Define ICE_THREAD_LOCAL_HACK to enable the pthread workarounds. 13 /// pthread. Define ICE_THREAD_LOCAL_HACK to enable the pthread workarounds.
14 /// 14 ///
15 //===----------------------------------------------------------------------===// 15 //===----------------------------------------------------------------------===//
16 16
17 #ifndef SUBZERO_SRC_ICETLS_H 17 #ifndef SUBZERO_SRC_ICETLS_H
18 #define SUBZERO_SRC_ICETLS_H 18 #define SUBZERO_SRC_ICETLS_H
19 19
20 #if defined(_MSC_VER)
21 #define ICE_ATTRIBUTE_TLS __declspec(thread)
22 #else // !_MSC_VER
23 #define ICE_ATTRIBUTE_TLS thread_local
24 #endif // !_MSC_VER
25 20
26 // Defines 4 macros for unifying thread_local and pthread: 21 ///
27 // 22 /// @defgroup /IceTLC Defines 5 macros for unifying thread_local and pthread:
Jim Stichnoth 2015/11/09 22:49:52 IceTLC? Should this be IceTLS?
rkotlerimgtec 2015/11/09 23:59:50 Done.
28 // ICE_TLS_DECLARE_FIELD(Type, FieldName): Declare a static thread_local field 23 /// @{
29 // inside the current class definition. "Type" needs to be a pointer type, such 24 ///
30 // as int* or class Foo*. 25 /// \def ICE_TLS_DECLARE_FIELD(Type, FieldName)
31 // 26 /// Declare a static thread_local field
Jim Stichnoth 2015/11/09 22:49:52 Reflow the remainders of all these comments to 80-
rkotlerimgtec 2015/11/09 23:59:50 Done.
32 // ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName): Define a static 27 /// inside the current class definition. "Type" needs to be a pointer type, such
33 // thread_local field outside of its class definition. The field will 28 /// as int* or class Foo*.
34 // ultimately be initialized to nullptr. 29 ///
35 // 30 /// \def ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName)
36 // ICE_TLS_INIT_FIELD(FieldName): Ensure the thread_local field is properly 31 /// Define a static
37 // initialized. This is intended to be called from within a static method of 32 /// thread_local field outside of its class definition. The field will
38 // the field's class after main() starts (to ensure that the pthread library is 33 /// ultimately be initialized to nullptr.
39 // fully initialized) but before any uses of ICE_TLS_GET_FIELD or 34 ///
40 // ICE_TLS_SET_FIELD. 35 /// \def ICE_TLS_INIT_FIELD(FieldName)
41 // 36 /// Ensure the thread_local field is properly initialized.
42 // ICE_TLS_GET_FIELD(Type, FieldName): Read the value of the static 37 /// This is intended to be called from within a static method of
43 // thread_local field. Must be done within the context of its class. 38 /// the field's class after main() starts (to ensure that the pthread library is
44 // 39 /// fully initialized) but before any uses of ICE_TLS_GET_FIELD or
45 // ICE_TLS_SET_FIELD(FieldName, Value): Write a value into the static 40 /// ICE_TLS_SET_FIELD.
46 // thread_local field. Must be done within the context of its class. 41 ///
42 /// \def ICE_TLS_GET_FIELD(Type, FieldName)
43 /// Read the value of the static
44 /// thread_local field. Must be done within the context of its class.
45 ///
46 /// \def ICE_TLS_SET_FIELD(FieldName, Value)
47 /// Write a value into the static
48 /// thread_local field. Must be done within the context of its class.
47 49
48 // TODO(stichnot): Limit this define to only the platforms that 50 /// \todo TODO(stichnot)
49 // absolutely require it. And ideally, eventually remove this hack 51 ///Limit this define to only the platforms that
50 // altogether. 52 /// absolutely require it. And ideally, eventually remove this hack
53 /// altogether.
54 ///
55
56 ///
57 /// \def ICE_THREAD_LOCAL_HACK
58 ///
51 #define ICE_THREAD_LOCAL_HACK 59 #define ICE_THREAD_LOCAL_HACK
52 #ifdef ICE_THREAD_LOCAL_HACK 60 #ifdef ICE_THREAD_LOCAL_HACK
53 61
54 // For a static thread_local field F of a class C, instead of declaring and 62 // For a static thread_local field F of a class C, instead of declaring and
55 // defining C::F, we create two static fields: 63 // defining C::F, we create two static fields:
56 // static pthread_key_t F__key; 64 // static pthread_key_t F__key;
57 // static int F__initStatus; 65 // static int F__initStatus;
58 // 66 //
59 // The F__initStatus field is used to hold the result of the 67 // The F__initStatus field is used to hold the result of the
60 // pthread_key_create() call, where a zero value indicates success, and a 68 // pthread_key_create() call, where a zero value indicates success, and a
(...skipping 18 matching lines...) Expand all
79 } 87 }
80 #define ICE_TLS_GET_FIELD(FieldName) \ 88 #define ICE_TLS_GET_FIELD(FieldName) \
81 (assert(FieldName##__initStatus == 0), \ 89 (assert(FieldName##__initStatus == 0), \
82 static_cast<FieldName##__type>(pthread_getspecific(FieldName##__key))) 90 static_cast<FieldName##__type>(pthread_getspecific(FieldName##__key)))
83 #define ICE_TLS_SET_FIELD(FieldName, Value) \ 91 #define ICE_TLS_SET_FIELD(FieldName, Value) \
84 (assert(FieldName##__initStatus == 0), \ 92 (assert(FieldName##__initStatus == 0), \
85 pthread_setspecific(FieldName##__key, (Value))) 93 pthread_setspecific(FieldName##__key, (Value)))
86 94
87 #else // !ICE_THREAD_LOCAL_HACK 95 #else // !ICE_THREAD_LOCAL_HACK
88 96
97 #if defined(_MSC_VER)
98 #define ICE_ATTRIBUTE_TLS __declspec(thread)
99 #else // !_MSC_VER
100 #define ICE_ATTRIBUTE_TLS thread_local
101 #endif // !_MSC_VER
102
103
89 #define ICE_TLS_DECLARE_FIELD(Type, FieldName) \ 104 #define ICE_TLS_DECLARE_FIELD(Type, FieldName) \
90 static ICE_ATTRIBUTE_TLS Type FieldName 105 static ICE_ATTRIBUTE_TLS Type FieldName
91 #define ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName) \ 106 #define ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName) \
92 ICE_ATTRIBUTE_TLS Type ClassName::FieldName = nullptr 107 ICE_ATTRIBUTE_TLS Type ClassName::FieldName = nullptr
93 #define ICE_TLS_INIT_FIELD(FieldName) 108 #define ICE_TLS_INIT_FIELD(FieldName)
94 #define ICE_TLS_GET_FIELD(FieldName) (FieldName) 109 #define ICE_TLS_GET_FIELD(FieldName) (FieldName)
95 #define ICE_TLS_SET_FIELD(FieldName, Value) (FieldName = (Value)) 110 #define ICE_TLS_SET_FIELD(FieldName, Value) (FieldName = (Value))
96 111
97 #endif // !ICE_THREAD_LOCAL_HACK 112 #endif // !ICE_THREAD_LOCAL_HACK
98 113
114 ///
115 /// @}
116 ///
117
99 #endif // SUBZERO_SRC_ICETLS_H 118 #endif // SUBZERO_SRC_ICETLS_H
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698