xref: /freebsd/contrib/llvm-project/libcxx/include/__thread/support/windows.h (revision b64c5a0ace59af62eff52bfe110a521dc73c937b)
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 
10 #ifndef _LIBCPP___THREAD_SUPPORT_WINDOWS_H
11 #define _LIBCPP___THREAD_SUPPORT_WINDOWS_H
12 
13 #include <__chrono/duration.h>
14 #include <__config>
15 #include <ctime>
16 
17 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
18 #  pragma GCC system_header
19 #endif
20 
21 _LIBCPP_BEGIN_NAMESPACE_STD
22 
23 using __libcpp_timespec_t = ::timespec;
24 
25 //
26 // Mutex
27 //
28 typedef void* __libcpp_mutex_t;
29 #define _LIBCPP_MUTEX_INITIALIZER 0
30 
31 #if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__)
32 typedef void* __libcpp_recursive_mutex_t[6];
33 #elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__)
34 typedef void* __libcpp_recursive_mutex_t[5];
35 #else
36 #  error Unsupported architecture
37 #endif
38 
39 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t* __m);
40 
41 _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int
42 __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t* __m);
43 
44 _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_NO_THREAD_SAFETY_ANALYSIS bool
45 __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t* __m);
46 
47 _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int
48 __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t* __m);
49 
50 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t* __m);
51 
52 _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_mutex_lock(__libcpp_mutex_t* __m);
53 
54 _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_NO_THREAD_SAFETY_ANALYSIS bool __libcpp_mutex_trylock(__libcpp_mutex_t* __m);
55 
56 _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_mutex_unlock(__libcpp_mutex_t* __m);
57 
58 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_mutex_destroy(__libcpp_mutex_t* __m);
59 
60 //
61 // Condition variable
62 //
63 typedef void* __libcpp_condvar_t;
64 #define _LIBCPP_CONDVAR_INITIALIZER 0
65 
66 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_condvar_signal(__libcpp_condvar_t* __cv);
67 
68 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv);
69 
70 _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int
71 __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m);
72 
73 _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int
74 __libcpp_condvar_timedwait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m, __libcpp_timespec_t* __ts);
75 
76 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
77 
78 //
79 // Execute once
80 //
81 typedef void* __libcpp_exec_once_flag;
82 #define _LIBCPP_EXEC_ONCE_INITIALIZER 0
83 
84 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_execute_once(__libcpp_exec_once_flag* __flag, void (*__init_routine)());
85 
86 //
87 // Thread id
88 //
89 typedef long __libcpp_thread_id;
90 
91 _LIBCPP_EXPORTED_FROM_ABI bool __libcpp_thread_id_equal(__libcpp_thread_id __t1, __libcpp_thread_id __t2);
92 
93 _LIBCPP_EXPORTED_FROM_ABI bool __libcpp_thread_id_less(__libcpp_thread_id __t1, __libcpp_thread_id __t2);
94 
95 //
96 // Thread
97 //
98 #define _LIBCPP_NULL_THREAD 0U
99 typedef void* __libcpp_thread_t;
100 
101 _LIBCPP_EXPORTED_FROM_ABI bool __libcpp_thread_isnull(const __libcpp_thread_t* __t);
102 
103 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_thread_create(__libcpp_thread_t* __t, void* (*__func)(void*), void* __arg);
104 
105 _LIBCPP_EXPORTED_FROM_ABI __libcpp_thread_id __libcpp_thread_get_current_id();
106 
107 _LIBCPP_EXPORTED_FROM_ABI __libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t* __t);
108 
109 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_thread_join(__libcpp_thread_t* __t);
110 
111 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_thread_detach(__libcpp_thread_t* __t);
112 
113 _LIBCPP_EXPORTED_FROM_ABI void __libcpp_thread_yield();
114 
115 _LIBCPP_EXPORTED_FROM_ABI void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns);
116 
117 //
118 // Thread local storage
119 //
120 typedef long __libcpp_tls_key;
121 
122 #define _LIBCPP_TLS_DESTRUCTOR_CC __stdcall
123 
124 _LIBCPP_EXPORTED_FROM_ABI int
125 __libcpp_tls_create(__libcpp_tls_key* __key, void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*));
126 
127 _LIBCPP_EXPORTED_FROM_ABI void* __libcpp_tls_get(__libcpp_tls_key __key);
128 
129 _LIBCPP_EXPORTED_FROM_ABI int __libcpp_tls_set(__libcpp_tls_key __key, void* __p);
130 
131 _LIBCPP_END_NAMESPACE_STD
132 
133 #endif // _LIBCPP___THREAD_SUPPORT_WINDOWS_H
134