| OLD | NEW |
| 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 // This file defines macros for working around the lack of support for | 10 // This file defines macros for working around the lack of support for |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // pthread_getspecific() and pthread_setspecific(). | 64 // pthread_getspecific() and pthread_setspecific(). |
| 65 | 65 |
| 66 #include <pthread.h> | 66 #include <pthread.h> |
| 67 | 67 |
| 68 #define ICE_TLS_DECLARE_FIELD(Type, FieldName) \ | 68 #define ICE_TLS_DECLARE_FIELD(Type, FieldName) \ |
| 69 typedef Type FieldName##__type; \ | 69 typedef Type FieldName##__type; \ |
| 70 static pthread_key_t FieldName##__key; \ | 70 static pthread_key_t FieldName##__key; \ |
| 71 static int FieldName##__initStatus | 71 static int FieldName##__initStatus |
| 72 #define ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName) \ | 72 #define ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName) \ |
| 73 pthread_key_t ClassName::FieldName##__key; \ | 73 pthread_key_t ClassName::FieldName##__key; \ |
| 74 int ClassName::FieldName##__initStatus = 1; | 74 int ClassName::FieldName##__initStatus = 1 |
| 75 #define ICE_TLS_INIT_FIELD(FieldName) \ | 75 #define ICE_TLS_INIT_FIELD(FieldName) \ |
| 76 if (FieldName##__initStatus) { \ | 76 if (FieldName##__initStatus) { \ |
| 77 FieldName##__initStatus = pthread_key_create(&FieldName##__key, nullptr); \ | 77 FieldName##__initStatus = pthread_key_create(&FieldName##__key, nullptr); \ |
| 78 if (FieldName##__initStatus) \ | 78 if (FieldName##__initStatus) \ |
| 79 llvm::report_fatal_error("Failed to create pthread key"); \ | 79 llvm::report_fatal_error("Failed to create pthread key"); \ |
| 80 } | 80 } |
| 81 #define ICE_TLS_GET_FIELD(FieldName) \ | 81 #define ICE_TLS_GET_FIELD(FieldName) \ |
| 82 (assert(FieldName##__initStatus == 0), \ | 82 (assert(FieldName##__initStatus == 0), \ |
| 83 static_cast<FieldName##__type>(pthread_getspecific(FieldName##__key))) | 83 static_cast<FieldName##__type>(pthread_getspecific(FieldName##__key))) |
| 84 #define ICE_TLS_SET_FIELD(FieldName, Value) \ | 84 #define ICE_TLS_SET_FIELD(FieldName, Value) \ |
| 85 (assert(FieldName##__initStatus == 0), \ | 85 (assert(FieldName##__initStatus == 0), \ |
| 86 pthread_setspecific(FieldName##__key, (Value))) | 86 pthread_setspecific(FieldName##__key, (Value))) |
| 87 | 87 |
| 88 #else // !ICE_THREAD_LOCAL_HACK | 88 #else // !ICE_THREAD_LOCAL_HACK |
| 89 | 89 |
| 90 #define ICE_TLS_DECLARE_FIELD(Type, FieldName) \ | 90 #define ICE_TLS_DECLARE_FIELD(Type, FieldName) \ |
| 91 static ICE_ATTRIBUTE_TLS Type FieldName | 91 static ICE_ATTRIBUTE_TLS Type FieldName |
| 92 #define ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName) \ | 92 #define ICE_TLS_DEFINE_FIELD(Type, ClassName, FieldName) \ |
| 93 ICE_ATTRIBUTE_TLS Type ClassName::FieldName = nullptr | 93 ICE_ATTRIBUTE_TLS Type ClassName::FieldName = nullptr |
| 94 #define ICE_TLS_INIT_FIELD(FieldName) | 94 #define ICE_TLS_INIT_FIELD(FieldName) |
| 95 #define ICE_TLS_GET_FIELD(FieldName) (FieldName) | 95 #define ICE_TLS_GET_FIELD(FieldName) (FieldName) |
| 96 #define ICE_TLS_SET_FIELD(FieldName, Value) (FieldName = (Value)) | 96 #define ICE_TLS_SET_FIELD(FieldName, Value) (FieldName = (Value)) |
| 97 | 97 |
| 98 #endif // !ICE_THREAD_LOCAL_HACK | 98 #endif // !ICE_THREAD_LOCAL_HACK |
| 99 | 99 |
| 100 #endif // SUBZERO_SRC_ICETLS_H | 100 #endif // SUBZERO_SRC_ICETLS_H |
| OLD | NEW |