__threading_support 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___THREADING_SUPPORT
  10. #define _LIBCPP___THREADING_SUPPORT
  11. #include <__availability>
  12. #include <__chrono/convert_to_timespec.h>
  13. #include <__chrono/duration.h>
  14. #include <__config>
  15. #include <__fwd/hash.h>
  16. #include <ctime>
  17. #include <errno.h>
  18. #ifdef __MVS__
  19. # include <__support/ibm/nanosleep.h>
  20. #endif
  21. #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
  22. # pragma GCC system_header
  23. #endif
  24. #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
  25. #error #include <__external_threading>
  26. #elif !defined(_LIBCPP_HAS_NO_THREADS)
  27. #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
  28. // Some platforms require <bits/atomic_wide_counter.h> in order for
  29. // PTHREAD_COND_INITIALIZER to be expanded. Normally that would come
  30. // in via <pthread.h>, but it's a non-modular header on those platforms,
  31. // so libc++'s <math.h> usually absorbs atomic_wide_counter.h into the
  32. // module with <math.h> and makes atomic_wide_counter.h invisible.
  33. // Include <math.h> here to work around that.
  34. # include <math.h>
  35. # include <pthread.h>
  36. # include <sched.h>
  37. #elif defined(_LIBCPP_HAS_THREAD_API_C11)
  38. # include <threads.h>
  39. #endif
  40. #if defined(_LIBCPP_HAS_THREAD_API_WIN32)
  41. #define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_EXPORTED_FROM_ABI
  42. #else
  43. #define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
  44. #endif
  45. typedef ::timespec __libcpp_timespec_t;
  46. #endif // !defined(_LIBCPP_HAS_NO_THREADS)
  47. _LIBCPP_BEGIN_NAMESPACE_STD
  48. #if !defined(_LIBCPP_HAS_NO_THREADS)
  49. #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
  50. // Mutex
  51. typedef pthread_mutex_t __libcpp_mutex_t;
  52. #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
  53. typedef pthread_mutex_t __libcpp_recursive_mutex_t;
  54. // Condition Variable
  55. typedef pthread_cond_t __libcpp_condvar_t;
  56. #define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
  57. // Execute once
  58. typedef pthread_once_t __libcpp_exec_once_flag;
  59. #define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
  60. // Thread id
  61. #if defined(__MVS__)
  62. typedef unsigned long long __libcpp_thread_id;
  63. #else
  64. typedef pthread_t __libcpp_thread_id;
  65. #endif
  66. // Thread
  67. #define _LIBCPP_NULL_THREAD ((__libcpp_thread_t()))
  68. typedef pthread_t __libcpp_thread_t;
  69. // Thread Local Storage
  70. typedef pthread_key_t __libcpp_tls_key;
  71. #define _LIBCPP_TLS_DESTRUCTOR_CC
  72. #elif defined(_LIBCPP_HAS_THREAD_API_C11)
  73. // Mutex
  74. typedef mtx_t __libcpp_mutex_t;
  75. // mtx_t is a struct so using {} for initialization is valid.
  76. #define _LIBCPP_MUTEX_INITIALIZER {}
  77. typedef mtx_t __libcpp_recursive_mutex_t;
  78. // Condition Variable
  79. typedef cnd_t __libcpp_condvar_t;
  80. // cnd_t is a struct so using {} for initialization is valid.
  81. #define _LIBCPP_CONDVAR_INITIALIZER {}
  82. // Execute once
  83. typedef ::once_flag __libcpp_exec_once_flag;
  84. #define _LIBCPP_EXEC_ONCE_INITIALIZER ONCE_FLAG_INIT
  85. // Thread id
  86. typedef thrd_t __libcpp_thread_id;
  87. // Thread
  88. #define _LIBCPP_NULL_THREAD 0U
  89. typedef thrd_t __libcpp_thread_t;
  90. // Thread Local Storage
  91. typedef tss_t __libcpp_tls_key;
  92. #define _LIBCPP_TLS_DESTRUCTOR_CC
  93. #elif !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
  94. // Mutex
  95. typedef void* __libcpp_mutex_t;
  96. #define _LIBCPP_MUTEX_INITIALIZER 0
  97. #if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__)
  98. typedef void* __libcpp_recursive_mutex_t[6];
  99. #elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__)
  100. typedef void* __libcpp_recursive_mutex_t[5];
  101. #else
  102. # error Unsupported architecture
  103. #endif
  104. // Condition Variable
  105. typedef void* __libcpp_condvar_t;
  106. #define _LIBCPP_CONDVAR_INITIALIZER 0
  107. // Execute Once
  108. typedef void* __libcpp_exec_once_flag;
  109. #define _LIBCPP_EXEC_ONCE_INITIALIZER 0
  110. // Thread ID
  111. typedef long __libcpp_thread_id;
  112. // Thread
  113. #define _LIBCPP_NULL_THREAD 0U
  114. typedef void* __libcpp_thread_t;
  115. // Thread Local Storage
  116. typedef long __libcpp_tls_key;
  117. #define _LIBCPP_TLS_DESTRUCTOR_CC __stdcall
  118. #endif // !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
  119. #if !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
  120. // Mutex
  121. _LIBCPP_THREAD_ABI_VISIBILITY
  122. int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m);
  123. _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
  124. int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m);
  125. _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
  126. bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m);
  127. _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
  128. int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m);
  129. _LIBCPP_THREAD_ABI_VISIBILITY
  130. int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m);
  131. _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
  132. int __libcpp_mutex_lock(__libcpp_mutex_t *__m);
  133. _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
  134. bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m);
  135. _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
  136. int __libcpp_mutex_unlock(__libcpp_mutex_t *__m);
  137. _LIBCPP_THREAD_ABI_VISIBILITY
  138. int __libcpp_mutex_destroy(__libcpp_mutex_t *__m);
  139. // Condition variable
  140. _LIBCPP_THREAD_ABI_VISIBILITY
  141. int __libcpp_condvar_signal(__libcpp_condvar_t* __cv);
  142. _LIBCPP_THREAD_ABI_VISIBILITY
  143. int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv);
  144. _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
  145. int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m);
  146. _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
  147. int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
  148. __libcpp_timespec_t *__ts);
  149. _LIBCPP_THREAD_ABI_VISIBILITY
  150. int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
  151. // Execute once
  152. _LIBCPP_THREAD_ABI_VISIBILITY
  153. int __libcpp_execute_once(__libcpp_exec_once_flag *__flag,
  154. void (*__init_routine)());
  155. // Thread id
  156. _LIBCPP_THREAD_ABI_VISIBILITY
  157. bool __libcpp_thread_id_equal(__libcpp_thread_id __t1, __libcpp_thread_id __t2);
  158. _LIBCPP_THREAD_ABI_VISIBILITY
  159. bool __libcpp_thread_id_less(__libcpp_thread_id __t1, __libcpp_thread_id __t2);
  160. // Thread
  161. _LIBCPP_THREAD_ABI_VISIBILITY
  162. bool __libcpp_thread_isnull(const __libcpp_thread_t *__t);
  163. _LIBCPP_THREAD_ABI_VISIBILITY
  164. int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
  165. void *__arg);
  166. _LIBCPP_THREAD_ABI_VISIBILITY
  167. __libcpp_thread_id __libcpp_thread_get_current_id();
  168. _LIBCPP_THREAD_ABI_VISIBILITY
  169. __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t);
  170. _LIBCPP_THREAD_ABI_VISIBILITY
  171. int __libcpp_thread_join(__libcpp_thread_t *__t);
  172. _LIBCPP_THREAD_ABI_VISIBILITY
  173. int __libcpp_thread_detach(__libcpp_thread_t *__t);
  174. _LIBCPP_THREAD_ABI_VISIBILITY
  175. void __libcpp_thread_yield();
  176. _LIBCPP_THREAD_ABI_VISIBILITY
  177. void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns);
  178. // Thread local storage
  179. _LIBCPP_THREAD_ABI_VISIBILITY
  180. int __libcpp_tls_create(__libcpp_tls_key* __key,
  181. void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*));
  182. _LIBCPP_THREAD_ABI_VISIBILITY
  183. void *__libcpp_tls_get(__libcpp_tls_key __key);
  184. _LIBCPP_THREAD_ABI_VISIBILITY
  185. int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
  186. #endif // !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
  187. #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
  188. int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
  189. {
  190. pthread_mutexattr_t __attr;
  191. int __ec = pthread_mutexattr_init(&__attr);
  192. if (__ec)
  193. return __ec;
  194. __ec = pthread_mutexattr_settype(&__attr, PTHREAD_MUTEX_RECURSIVE);
  195. if (__ec) {
  196. pthread_mutexattr_destroy(&__attr);
  197. return __ec;
  198. }
  199. __ec = pthread_mutex_init(__m, &__attr);
  200. if (__ec) {
  201. pthread_mutexattr_destroy(&__attr);
  202. return __ec;
  203. }
  204. __ec = pthread_mutexattr_destroy(&__attr);
  205. if (__ec) {
  206. pthread_mutex_destroy(__m);
  207. return __ec;
  208. }
  209. return 0;
  210. }
  211. int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m)
  212. {
  213. return pthread_mutex_lock(__m);
  214. }
  215. bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
  216. {
  217. return pthread_mutex_trylock(__m) == 0;
  218. }
  219. int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m)
  220. {
  221. return pthread_mutex_unlock(__m);
  222. }
  223. int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m)
  224. {
  225. return pthread_mutex_destroy(__m);
  226. }
  227. int __libcpp_mutex_lock(__libcpp_mutex_t *__m)
  228. {
  229. return pthread_mutex_lock(__m);
  230. }
  231. bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
  232. {
  233. return pthread_mutex_trylock(__m) == 0;
  234. }
  235. int __libcpp_mutex_unlock(__libcpp_mutex_t *__m)
  236. {
  237. return pthread_mutex_unlock(__m);
  238. }
  239. int __libcpp_mutex_destroy(__libcpp_mutex_t *__m)
  240. {
  241. return pthread_mutex_destroy(__m);
  242. }
  243. // Condition Variable
  244. int __libcpp_condvar_signal(__libcpp_condvar_t *__cv)
  245. {
  246. return pthread_cond_signal(__cv);
  247. }
  248. int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv)
  249. {
  250. return pthread_cond_broadcast(__cv);
  251. }
  252. int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m)
  253. {
  254. return pthread_cond_wait(__cv, __m);
  255. }
  256. int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
  257. __libcpp_timespec_t *__ts)
  258. {
  259. return pthread_cond_timedwait(__cv, __m, __ts);
  260. }
  261. int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
  262. {
  263. return pthread_cond_destroy(__cv);
  264. }
  265. // Execute once
  266. int __libcpp_execute_once(__libcpp_exec_once_flag *__flag,
  267. void (*__init_routine)()) {
  268. return pthread_once(__flag, __init_routine);
  269. }
  270. // Thread id
  271. // Returns non-zero if the thread ids are equal, otherwise 0
  272. bool __libcpp_thread_id_equal(__libcpp_thread_id __t1, __libcpp_thread_id __t2)
  273. {
  274. return __t1 == __t2;
  275. }
  276. // Returns non-zero if t1 < t2, otherwise 0
  277. bool __libcpp_thread_id_less(__libcpp_thread_id __t1, __libcpp_thread_id __t2)
  278. {
  279. return __t1 < __t2;
  280. }
  281. // Thread
  282. bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
  283. return __libcpp_thread_get_id(__t) == 0;
  284. }
  285. int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
  286. void *__arg)
  287. {
  288. return pthread_create(__t, nullptr, __func, __arg);
  289. }
  290. __libcpp_thread_id __libcpp_thread_get_current_id()
  291. {
  292. const __libcpp_thread_t __current_thread = pthread_self();
  293. return __libcpp_thread_get_id(&__current_thread);
  294. }
  295. __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t)
  296. {
  297. #if defined(__MVS__)
  298. return __t->__;
  299. #else
  300. return *__t;
  301. #endif
  302. }
  303. int __libcpp_thread_join(__libcpp_thread_t *__t)
  304. {
  305. return pthread_join(*__t, nullptr);
  306. }
  307. int __libcpp_thread_detach(__libcpp_thread_t *__t)
  308. {
  309. return pthread_detach(*__t);
  310. }
  311. void __libcpp_thread_yield()
  312. {
  313. sched_yield();
  314. }
  315. void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
  316. {
  317. __libcpp_timespec_t __ts = _VSTD::__convert_to_timespec<__libcpp_timespec_t>(__ns);
  318. while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
  319. }
  320. // Thread local storage
  321. int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
  322. {
  323. return pthread_key_create(__key, __at_exit);
  324. }
  325. void *__libcpp_tls_get(__libcpp_tls_key __key)
  326. {
  327. return pthread_getspecific(__key);
  328. }
  329. int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
  330. {
  331. return pthread_setspecific(__key, __p);
  332. }
  333. #elif defined(_LIBCPP_HAS_THREAD_API_C11)
  334. int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
  335. {
  336. return mtx_init(__m, mtx_plain | mtx_recursive) == thrd_success ? 0 : EINVAL;
  337. }
  338. int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m)
  339. {
  340. return mtx_lock(__m) == thrd_success ? 0 : EINVAL;
  341. }
  342. bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
  343. {
  344. return mtx_trylock(__m) == thrd_success;
  345. }
  346. int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m)
  347. {
  348. return mtx_unlock(__m) == thrd_success ? 0 : EINVAL;
  349. }
  350. int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m)
  351. {
  352. mtx_destroy(__m);
  353. return 0;
  354. }
  355. int __libcpp_mutex_lock(__libcpp_mutex_t *__m)
  356. {
  357. return mtx_lock(__m) == thrd_success ? 0 : EINVAL;
  358. }
  359. bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
  360. {
  361. return mtx_trylock(__m) == thrd_success;
  362. }
  363. int __libcpp_mutex_unlock(__libcpp_mutex_t *__m)
  364. {
  365. return mtx_unlock(__m) == thrd_success ? 0 : EINVAL;
  366. }
  367. int __libcpp_mutex_destroy(__libcpp_mutex_t *__m)
  368. {
  369. mtx_destroy(__m);
  370. return 0;
  371. }
  372. // Condition Variable
  373. int __libcpp_condvar_signal(__libcpp_condvar_t *__cv)
  374. {
  375. return cnd_signal(__cv) == thrd_success ? 0 : EINVAL;
  376. }
  377. int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv)
  378. {
  379. return cnd_broadcast(__cv) == thrd_success ? 0 : EINVAL;
  380. }
  381. int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m)
  382. {
  383. return cnd_wait(__cv, __m) == thrd_success ? 0 : EINVAL;
  384. }
  385. int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
  386. timespec *__ts)
  387. {
  388. int __ec = cnd_timedwait(__cv, __m, __ts);
  389. return __ec == thrd_timedout ? ETIMEDOUT : __ec;
  390. }
  391. int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
  392. {
  393. cnd_destroy(__cv);
  394. return 0;
  395. }
  396. // Execute once
  397. int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
  398. void (*init_routine)(void)) {
  399. ::call_once(flag, init_routine);
  400. return 0;
  401. }
  402. // Thread id
  403. // Returns non-zero if the thread ids are equal, otherwise 0
  404. bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
  405. {
  406. return thrd_equal(t1, t2) != 0;
  407. }
  408. // Returns non-zero if t1 < t2, otherwise 0
  409. bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2)
  410. {
  411. return t1 < t2;
  412. }
  413. // Thread
  414. bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
  415. return __libcpp_thread_get_id(__t) == 0;
  416. }
  417. int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
  418. void *__arg)
  419. {
  420. int __ec = thrd_create(__t, reinterpret_cast<thrd_start_t>(__func), __arg);
  421. return __ec == thrd_nomem ? ENOMEM : __ec;
  422. }
  423. __libcpp_thread_id __libcpp_thread_get_current_id()
  424. {
  425. return thrd_current();
  426. }
  427. __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t)
  428. {
  429. return *__t;
  430. }
  431. int __libcpp_thread_join(__libcpp_thread_t *__t)
  432. {
  433. return thrd_join(*__t, nullptr) == thrd_success ? 0 : EINVAL;
  434. }
  435. int __libcpp_thread_detach(__libcpp_thread_t *__t)
  436. {
  437. return thrd_detach(*__t) == thrd_success ? 0 : EINVAL;
  438. }
  439. void __libcpp_thread_yield()
  440. {
  441. thrd_yield();
  442. }
  443. void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
  444. {
  445. __libcpp_timespec_t __ts = _VSTD::__convert_to_timespec<__libcpp_timespec_t>(__ns);
  446. thrd_sleep(&__ts, nullptr);
  447. }
  448. // Thread local storage
  449. int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
  450. {
  451. return tss_create(__key, __at_exit) == thrd_success ? 0 : EINVAL;
  452. }
  453. void *__libcpp_tls_get(__libcpp_tls_key __key)
  454. {
  455. return tss_get(__key);
  456. }
  457. int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
  458. {
  459. return tss_set(__key, __p) == thrd_success ? 0 : EINVAL;
  460. }
  461. #endif
  462. #endif // !_LIBCPP_HAS_NO_THREADS
  463. _LIBCPP_END_NAMESPACE_STD
  464. #endif // _LIBCPP___THREADING_SUPPORT