10 #ifndef EIGEN_CXX11_THREADPOOL_THREAD_LOCAL_H
11 #define EIGEN_CXX11_THREADPOOL_THREAD_LOCAL_H
13 #ifdef EIGEN_AVOID_THREAD_LOCAL
15 #ifdef EIGEN_THREAD_LOCAL
16 #undef EIGEN_THREAD_LOCAL
21 #if EIGEN_MAX_CPP_VER >= 11 && \
22 ((EIGEN_COMP_GNUC && EIGEN_GNUC_AT_LEAST(4, 8)) || \
23 __has_feature(cxx_thread_local) || \
24 (EIGEN_COMP_MSVC >= 1900) )
25 #define EIGEN_THREAD_LOCAL static thread_local
29 #if defined(__APPLE__)
32 #include <Availability.h>
33 #include <TargetConditionals.h>
37 #if defined(__apple_build_version__) && \
38 ((__apple_build_version__ < 8000042) || \
39 (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0))
42 #undef EIGEN_THREAD_LOCAL
44 #elif defined(__ANDROID__) && EIGEN_COMP_CLANG
53 #if __has_include(<android/ndk-version.h>)
54 #include <android/ndk-version.h>
55 #endif // __has_include(<android/ndk-version.h>)
56 #if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
57 defined(__NDK_MINOR__) && \
58 ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
59 #undef EIGEN_THREAD_LOCAL
61 #endif // defined(__ANDROID__) && defined(__clang__)
63 #endif // EIGEN_AVOID_THREAD_LOCAL
112 template <
typename T,
113 typename Initialize = internal::ThreadLocalNoOpInitialize<T>,
114 typename Release = internal::ThreadLocalNoOpRelease<T>>
118 "ThreadLocal data type must be default constructible");
123 internal::ThreadLocalNoOpRelease<
T>()) {}
127 internal::ThreadLocalNoOpRelease<
T>()) {}
139 ptr_.emplace_back(
nullptr);
147 std::size_t h = std::hash<std::thread::id>()(this_thread);
159 while (
ptr_[idx].load() !=
nullptr) {
165 if (idx == start_idx)
break;
178 int insertion_index =
184 data_[insertion_index].thread_id = this_thread;
197 const int insertion_idx = idx;
202 while (
ptr_[idx].load() !=
nullptr) {
211 }
while (!
ptr_[idx].compare_exchange_weak(
empty, inserted));
213 return inserted->
value;
220 for (
auto& ptr :
ptr_) {
222 if (record ==
nullptr)
continue;
230 std::unique_lock<std::mutex> lock(
mu_);
232 f(kv.first, kv.second);
240 for (
auto& ptr :
ptr_) {
242 if (record ==
nullptr)
continue;
250 std::unique_lock<std::mutex> lock(
mu_);
264 std::unique_lock<std::mutex> lock(
mu_);
271 return (*
result.first).second;
301 #endif // EIGEN_CXX11_THREADPOOL_THREAD_LOCAL_H