comparison libcxx/src/thread.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
4 // See https://llvm.org/LICENSE.txt for license information. 4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 // 6 //
7 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
8 8
9 #include "__config" 9 #include <__config>
10
10 #ifndef _LIBCPP_HAS_NO_THREADS 11 #ifndef _LIBCPP_HAS_NO_THREADS
11 12
12 #include "thread" 13 #include <exception>
13 #include "exception" 14 #include <future>
14 #include "vector" 15 #include <limits>
15 #include "future" 16 #include <thread>
16 #include "limits" 17 #include <vector>
17 18
18 #if __has_include(<unistd.h>) 19 #if __has_include(<unistd.h>)
19 # include <unistd.h> // for sysconf 20 # include <unistd.h> // for sysconf
20 #endif 21 #endif
21 22
112 } // this_thread 113 } // this_thread
113 114
114 __thread_specific_ptr<__thread_struct>& 115 __thread_specific_ptr<__thread_struct>&
115 __thread_local_data() 116 __thread_local_data()
116 { 117 {
117 static __thread_specific_ptr<__thread_struct> __p; 118 // Even though __thread_specific_ptr's destructor doesn't actually destroy
118 return __p; 119 // anything (see comments there), we can't call it at all because threads may
120 // outlive the static variable and calling its destructor means accessing an
121 // object outside of its lifetime, which is UB.
122 alignas(__thread_specific_ptr<__thread_struct>) static char __b[sizeof(__thread_specific_ptr<__thread_struct>)];
123 static __thread_specific_ptr<__thread_struct>* __p = new (__b) __thread_specific_ptr<__thread_struct>();
124 return *__p;
119 } 125 }
120 126
121 // __thread_struct_imp 127 // __thread_struct_imp
122 128
123 template <class T> 129 template <class T>