|
| 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_H |
| 11 | +#define _LIBCPP___THREAD_SUPPORT_H |
| 12 | + |
| 13 | +#include <__config> |
| 14 | + |
| 15 | +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER |
| 16 | +# pragma GCC system_header |
| 17 | +#endif |
| 18 | + |
| 19 | +/* |
| 20 | +
|
| 21 | +// |
| 22 | +// The library supports multiple implementations of the basic threading functionality. |
| 23 | +// The following functionality must be provided by any implementation: |
| 24 | +// |
| 25 | +
|
| 26 | +using __libcpp_timespec_t = ...; |
| 27 | +
|
| 28 | +// |
| 29 | +// Mutex |
| 30 | +// |
| 31 | +using __libcpp_mutex_t = ...; |
| 32 | +#define _LIBCPP_MUTEX_INITIALIZER ... |
| 33 | +
|
| 34 | +using __libcpp_recursive_mutex_t = ...; |
| 35 | +
|
| 36 | +int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t*); |
| 37 | +_LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t*); |
| 38 | +_LIBCPP_NO_THREAD_SAFETY_ANALYSIS bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t*); |
| 39 | +_LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t*); |
| 40 | +int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t*); |
| 41 | +
|
| 42 | +_LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_mutex_lock(__libcpp_mutex_t*); |
| 43 | +_LIBCPP_NO_THREAD_SAFETY_ANALYSIS bool __libcpp_mutex_trylock(__libcpp_mutex_t*); |
| 44 | +_LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_mutex_unlock(__libcpp_mutex_t*); |
| 45 | +int __libcpp_mutex_destroy(__libcpp_mutex_t*); |
| 46 | +
|
| 47 | +// |
| 48 | +// Condition Variable |
| 49 | +// |
| 50 | +using __libcpp_condvar_t = ...; |
| 51 | +#define _LIBCPP_CONDVAR_INITIALIZER ... |
| 52 | +
|
| 53 | +int __libcpp_condvar_signal(__libcpp_condvar_t*); |
| 54 | +int __libcpp_condvar_broadcast(__libcpp_condvar_t*); |
| 55 | +_LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_condvar_wait(__libcpp_condvar_t*, __libcpp_mutex_t*); |
| 56 | +_LIBCPP_NO_THREAD_SAFETY_ANALYSIS |
| 57 | +int __libcpp_condvar_timedwait(__libcpp_condvar_t*, __libcpp_mutex_t*, __libcpp_timespec_t*); |
| 58 | +int __libcpp_condvar_destroy(__libcpp_condvar_t*); |
| 59 | +
|
| 60 | +// |
| 61 | +// Execute once |
| 62 | +// |
| 63 | +using __libcpp_exec_once_flag = ...; |
| 64 | +#define _LIBCPP_EXEC_ONCE_INITIALIZER ... |
| 65 | +
|
| 66 | +int __libcpp_execute_once(__libcpp_exec_once_flag*, void (*__init_routine)()); |
| 67 | +
|
| 68 | +// |
| 69 | +// Thread id |
| 70 | +// |
| 71 | +using __libcpp_thread_id = ...; |
| 72 | +
|
| 73 | +bool __libcpp_thread_id_equal(__libcpp_thread_id, __libcpp_thread_id); |
| 74 | +bool __libcpp_thread_id_less(__libcpp_thread_id, __libcpp_thread_id); |
| 75 | +
|
| 76 | +// |
| 77 | +// Thread |
| 78 | +// |
| 79 | +#define _LIBCPP_NULL_THREAD ... |
| 80 | +using __libcpp_thread_t = ...; |
| 81 | +
|
| 82 | +bool __libcpp_thread_isnull(const __libcpp_thread_t*); |
| 83 | +int __libcpp_thread_create(__libcpp_thread_t*, void* (*__func)(void*), void* __arg); |
| 84 | +__libcpp_thread_id __libcpp_thread_get_current_id(); |
| 85 | +__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t*); |
| 86 | +int __libcpp_thread_join(__libcpp_thread_t*); |
| 87 | +int __libcpp_thread_detach(__libcpp_thread_t*); |
| 88 | +void __libcpp_thread_yield(); |
| 89 | +void __libcpp_thread_sleep_for(const chrono::nanoseconds&); |
| 90 | +
|
| 91 | +// |
| 92 | +// Thread local storage |
| 93 | +// |
| 94 | +#define _LIBCPP_TLS_DESTRUCTOR_CC ... |
| 95 | +using __libcpp_tls_key = ...; |
| 96 | +
|
| 97 | +int __libcpp_tls_create(__libcpp_tls_key*, void (*__at_exit)(void*)); |
| 98 | +void* __libcpp_tls_get(__libcpp_tls_key); |
| 99 | +int __libcpp_tls_set(__libcpp_tls_key, void*); |
| 100 | +
|
| 101 | +*/ |
| 102 | + |
| 103 | +#if !defined(_LIBCPP_HAS_NO_THREADS) |
| 104 | + |
| 105 | +# if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) |
| 106 | +# include <__thread/support/external.h> |
| 107 | +# elif defined(_LIBCPP_HAS_THREAD_API_PTHREAD) |
| 108 | +# include <__thread/support/pthread.h> |
| 109 | +# elif defined(_LIBCPP_HAS_THREAD_API_C11) |
| 110 | +# include <__thread/support/c11.h> |
| 111 | +# elif defined(_LIBCPP_HAS_THREAD_API_WIN32) |
| 112 | +# include <__thread/support/windows.h> |
| 113 | +# else |
| 114 | +# error "No threading API was selected" |
| 115 | +# endif |
| 116 | + |
| 117 | +#endif // !_LIBCPP_HAS_NO_THREADS |
| 118 | + |
| 119 | +#endif // _LIBCPP___THREAD_SUPPORT_H |
0 commit comments