| 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___CXX03___THREAD_SUPPORT_H |
| 11 |
#define _LIBCPP___CXX03___THREAD_SUPPORT_H |
| 12 |
|
| 13 |
#include <__cxx03/__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 |
_LIBCPP_BEGIN_NAMESPACE_STD |
| 27 |
|
| 28 |
using __libcpp_timespec_t = ...; |
| 29 |
|
| 30 |
// |
| 31 |
// Mutex |
| 32 |
// |
| 33 |
using __libcpp_mutex_t = ...; |
| 34 |
#define _LIBCPP_MUTEX_INITIALIZER ... |
| 35 |
|
| 36 |
using __libcpp_recursive_mutex_t = ...; |
| 37 |
|
| 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*); |
| 43 |
|
| 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*); |
| 48 |
|
| 49 |
// |
| 50 |
// Condition Variable |
| 51 |
// |
| 52 |
using __libcpp_condvar_t = ...; |
| 53 |
#define _LIBCPP_CONDVAR_INITIALIZER ... |
| 54 |
|
| 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*); |
| 61 |
|
| 62 |
// |
| 63 |
// Execute once |
| 64 |
// |
| 65 |
using __libcpp_exec_once_flag = ...; |
| 66 |
#define _LIBCPP_EXEC_ONCE_INITIALIZER ... |
| 67 |
|
| 68 |
int __libcpp_execute_once(__libcpp_exec_once_flag*, void (*__init_routine)()); |
| 69 |
|
| 70 |
// |
| 71 |
// Thread id |
| 72 |
// |
| 73 |
using __libcpp_thread_id = ...; |
| 74 |
|
| 75 |
bool __libcpp_thread_id_equal(__libcpp_thread_id, __libcpp_thread_id); |
| 76 |
bool __libcpp_thread_id_less(__libcpp_thread_id, __libcpp_thread_id); |
| 77 |
|
| 78 |
// |
| 79 |
// Thread |
| 80 |
// |
| 81 |
#define _LIBCPP_NULL_THREAD ... |
| 82 |
using __libcpp_thread_t = ...; |
| 83 |
|
| 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&); |
| 92 |
|
| 93 |
// |
| 94 |
// Thread local storage |
| 95 |
// |
| 96 |
#define _LIBCPP_TLS_DESTRUCTOR_CC ... |
| 97 |
using __libcpp_tls_key = ...; |
| 98 |
|
| 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*); |
| 102 |
|
| 103 |
_LIBCPP_END_NAMESPACE_STD |
| 104 |
|
| 105 |
*/ |
| 106 |
|
| 107 |
#if !defined(_LIBCPP_HAS_NO_THREADS) |
| 108 |
|
| 109 |
# if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) |
| 110 |
# include <__cxx03/__thread/support/external.h> |
| 111 |
# elif defined(_LIBCPP_HAS_THREAD_API_PTHREAD) |
| 112 |
# include <__cxx03/__thread/support/pthread.h> |
| 113 |
# elif defined(_LIBCPP_HAS_THREAD_API_C11) |
| 114 |
# include <__cxx03/__thread/support/c11.h> |
| 115 |
# elif defined(_LIBCPP_HAS_THREAD_API_WIN32) |
| 116 |
# include <__cxx03/__thread/support/windows.h> |
| 117 |
# else |
| 118 |
# error "No threading API was selected" |
| 119 |
# endif |
| 120 |
|
| 121 |
#endif // !_LIBCPP_HAS_NO_THREADS |
| 122 |
|
| 123 |
#endif // _LIBCPP___CXX03___THREAD_SUPPORT_H |