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

Side by Side Diff: src/IceTLS.h

Issue 872933002: Subzero: Second attempt at fixing MacOS 10.6 build. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Change macro argument order Created 5 years, 11 months 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 | « src/IceGlobalContext.cpp ('k') | 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
(Empty)
1 //===- subzero/src/IceTLS.h - thread_local workaround -----------*- C++ -*-===//
2 //
3 // The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines macros for working around the lack of support for
11 // thread_local in MacOS 10.6. It assumes std::thread is written in
12 // terms of pthread. Define ICE_THREAD_LOCAL_HACK to enable the
13 // pthread workarounds.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef SUBZERO_SRC_ICETLS_H
18 #define SUBZERO_SRC_ICETLS_H
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
26 // Defines 4 macros for unifying thread_local and pthread:
27 //
28 // ICE_TLS_DECLARE_FIELD(Type, FieldName): Declare a static
29 // thread_local field inside the current class definition. "Type"
30 // needs to be a pointer type, such as int* or class Foo*.
31 //
32 // ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName): Define a static
33 // thread_local field outside of its class definition, and initialize
34 // it to nullptr.
35 //
36 // ICE_TLS_GET_FIELD(Type, FieldName): Read the value of the static
37 // thread_local field. Must be done within the context of its class.
38 //
39 // ICE_TLS_SET_FIELD(FieldName, Value): Write a value into the static
40 // thread_local field. Must be done within the context of its class.
41
42 #ifdef ICE_THREAD_LOCAL_HACK
43
44 // For a static thread_local field F of a class C, instead of
45 // declaring and defining F::C, we create two static fields:
jvoung (off chromium) 2015/01/24 18:47:40 "instead of declaring and defining C::F" ?
Jim Stichnoth 2015/01/24 21:47:30 Done.
46 // static pthread_key_t F__key;
47 // static int F__dummy;
48 //
49 // The F__dummy field is just used to hold the result of the
50 // pthread_key_create() call, which is executed as a static
51 // initializer. The F__key field is used as the argument to
52 // pthread_getspecific() and pthread_setspecific().
53
54 #include <pthread.h>
55
56 #define ICE_TLS_DECLARE_FIELD(Type, FieldName) \
57 static pthread_key_t FieldName##__key; \
58 static int FieldName##__dummy
59 #define ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName) \
60 pthread_key_t ClassName::FieldName##__key; \
61 int ClassName::FieldName##__dummy = \
62 pthread_key_create(&ClassName::FieldName##__key, nullptr)
63 #define ICE_TLS_GET_FIELD(Type, FieldName) \
64 static_cast<Type>(pthread_getspecific(FieldName##__key))
65 #define ICE_TLS_SET_FIELD(FieldName, Value) \
66 pthread_setspecific(FieldName##__key, (Value))
67
68 #else // !ICE_THREAD_LOCAL_HACK
69
70 #define ICE_TLS_DECLARE_FIELD(Type, FieldName) \
71 static ICE_ATTRIBUTE_TLS Type FieldName
72 #define ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName) \
73 ICE_ATTRIBUTE_TLS Type ClassName::FieldName = nullptr
74 #define ICE_TLS_GET_FIELD(Type, FieldName) (FieldName)
75 #define ICE_TLS_SET_FIELD(FieldName, Value) (FieldName = (Value))
76
77 #endif // !ICE_THREAD_LOCAL_HACK
78
79 #endif // SUBZERO_SRC_ICETLS_H
OLDNEW
« no previous file with comments | « src/IceGlobalContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698