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_LIBCPP_BEGIN_NAMESPACE_STD
27
28using __libcpp_timespec_t = ...;
29
30//
31// Mutex
32//
33using __libcpp_mutex_t = ...;
34#define _LIBCPP_MUTEX_INITIALIZER ...
35
36using __libcpp_recursive_mutex_t = ...;
37
38int __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*);
42int __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*);
47int __libcpp_mutex_destroy(__libcpp_mutex_t*);
48
49//
50// Condition Variable
51//
52using __libcpp_condvar_t = ...;
53#define _LIBCPP_CONDVAR_INITIALIZER ...
54
55int __libcpp_condvar_signal(__libcpp_condvar_t*);
56int __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
59int __libcpp_condvar_timedwait(__libcpp_condvar_t*, __libcpp_mutex_t*, __libcpp_timespec_t*);
60int __libcpp_condvar_destroy(__libcpp_condvar_t*);
61
62//
63// Execute once
64//
65using __libcpp_exec_once_flag = ...;
66#define _LIBCPP_EXEC_ONCE_INITIALIZER ...
67
68int __libcpp_execute_once(__libcpp_exec_once_flag*, void (*__init_routine)());
69
70//
71// Thread id
72//
73using __libcpp_thread_id = ...;
74
75bool __libcpp_thread_id_equal(__libcpp_thread_id, __libcpp_thread_id);
76bool __libcpp_thread_id_less(__libcpp_thread_id, __libcpp_thread_id);
77
78//
79// Thread
80//
81#define _LIBCPP_NULL_THREAD ...
82using __libcpp_thread_t = ...;
83
84bool __libcpp_thread_isnull(const __libcpp_thread_t*);
85int __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*);
88int __libcpp_thread_join(__libcpp_thread_t*);
89int __libcpp_thread_detach(__libcpp_thread_t*);
90void __libcpp_thread_yield();
91void __libcpp_thread_sleep_for(const chrono::nanoseconds&);
92
93//
94// Thread local storage
95//
96#define _LIBCPP_TLS_DESTRUCTOR_CC ...
97using __libcpp_tls_key = ...;
98
99int __libcpp_tls_create(__libcpp_tls_key*, void (*__at_exit)(void*));
100void* __libcpp_tls_get(__libcpp_tls_key);
101int __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 <__thread/support/external.h>
111# elif defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
112# include <__thread/support/pthread.h>
113# elif defined(_LIBCPP_HAS_THREAD_API_C11)
114# include <__thread/support/c11.h>
115# elif defined(_LIBCPP_HAS_THREAD_API_WIN32)
116# include <__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___THREAD_SUPPORT_H
124