2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___THREAD_SUPPORT_H
11 #define _LIBCPP___THREAD_SUPPORT_H
15 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
16 # pragma GCC system_header
22 // The library supports multiple implementations of the basic threading functionality.
23 // The following functionality must be provided by any implementation:
26 _LIBCPP_BEGIN_NAMESPACE_STD
28 using __libcpp_timespec_t = ...;
33 using __libcpp_mutex_t = ...;
34 #define _LIBCPP_MUTEX_INITIALIZER ...
36 using __libcpp_recursive_mutex_t = ...;
38 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t*);
39 _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t*);
40 _LIBCPP_NO_THREAD_SAFETY_ANALYSIS bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t*);
41 _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t*);
42 int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t*);
44 _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_mutex_lock(__libcpp_mutex_t*);
45 _LIBCPP_NO_THREAD_SAFETY_ANALYSIS bool __libcpp_mutex_trylock(__libcpp_mutex_t*);
46 _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_mutex_unlock(__libcpp_mutex_t*);
47 int __libcpp_mutex_destroy(__libcpp_mutex_t*);
52 using __libcpp_condvar_t = ...;
53 #define _LIBCPP_CONDVAR_INITIALIZER ...
55 int __libcpp_condvar_signal(__libcpp_condvar_t*);
56 int __libcpp_condvar_broadcast(__libcpp_condvar_t*);
57 _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_condvar_wait(__libcpp_condvar_t*, __libcpp_mutex_t*);
58 _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
59 int __libcpp_condvar_timedwait(__libcpp_condvar_t*, __libcpp_mutex_t*, __libcpp_timespec_t*);
60 int __libcpp_condvar_destroy(__libcpp_condvar_t*);
65 using __libcpp_exec_once_flag = ...;
66 #define _LIBCPP_EXEC_ONCE_INITIALIZER ...
68 int __libcpp_execute_once(__libcpp_exec_once_flag*, void (*__init_routine)());
73 using __libcpp_thread_id = ...;
75 bool __libcpp_thread_id_equal(__libcpp_thread_id, __libcpp_thread_id);
76 bool __libcpp_thread_id_less(__libcpp_thread_id, __libcpp_thread_id);
81 #define _LIBCPP_NULL_THREAD ...
82 using __libcpp_thread_t = ...;
84 bool __libcpp_thread_isnull(const __libcpp_thread_t*);
85 int __libcpp_thread_create(__libcpp_thread_t*, void* (*__func)(void*), void* __arg);
86 __libcpp_thread_id __libcpp_thread_get_current_id();
87 __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t*);
88 int __libcpp_thread_join(__libcpp_thread_t*);
89 int __libcpp_thread_detach(__libcpp_thread_t*);
90 void __libcpp_thread_yield();
91 void __libcpp_thread_sleep_for(const chrono::nanoseconds&);
94 // Thread local storage
96 #define _LIBCPP_TLS_DESTRUCTOR_CC ...
97 using __libcpp_tls_key = ...;
99 int __libcpp_tls_create(__libcpp_tls_key*, void (*__at_exit)(void*));
100 void* __libcpp_tls_get(__libcpp_tls_key);
101 int __libcpp_tls_set(__libcpp_tls_key, void*);
103 _LIBCPP_END_NAMESPACE_STD
107 #if _LIBCPP_HAS_THREADS
109 # if _LIBCPP_HAS_THREAD_API_EXTERNAL
110 # include <__thread/support/external.h>
111 # elif _LIBCPP_HAS_THREAD_API_PTHREAD
112 # include <__thread/support/pthread.h>
113 # elif _LIBCPP_HAS_THREAD_API_C11
114 # include <__thread/support/c11.h>
115 # elif _LIBCPP_HAS_THREAD_API_WIN32
116 # include <__thread/support/windows.h>
118 # error "No threading API was selected"
121 #endif // _LIBCPP_HAS_THREADS
123 #endif // _LIBCPP___THREAD_SUPPORT_H