xref: /freebsd/contrib/llvm-project/libcxx/include/thread (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
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
11#define _LIBCPP_THREAD
12
13/*
14
15    thread synopsis
16
17namespace std
18{
19
20class thread
21{
22public:
23    class id;
24    typedef pthread_t native_handle_type;
25
26    thread() noexcept;
27    template <class F, class ...Args> explicit thread(F&& f, Args&&... args);
28    ~thread();
29
30    thread(const thread&) = delete;
31    thread(thread&& t) noexcept;
32
33    thread& operator=(const thread&) = delete;
34    thread& operator=(thread&& t) noexcept;
35
36    void swap(thread& t) noexcept;
37
38    bool joinable() const noexcept;
39    void join();
40    void detach();
41    id get_id() const noexcept;
42    native_handle_type native_handle();
43
44    static unsigned hardware_concurrency() noexcept;
45};
46
47void swap(thread& x, thread& y) noexcept;
48
49class thread::id
50{
51public:
52    id() noexcept;
53};
54
55bool operator==(thread::id x, thread::id y) noexcept;
56bool operator!=(thread::id x, thread::id y) noexcept;             // removed in C++20
57bool operator< (thread::id x, thread::id y) noexcept;             // removed in C++20
58bool operator<=(thread::id x, thread::id y) noexcept;             // removed in C++20
59bool operator> (thread::id x, thread::id y) noexcept;             // removed in C++20
60bool operator>=(thread::id x, thread::id y) noexcept;             // removed in C++20
61strong_ordering operator<=>(thread::id x, thread::id y) noexcept; // C++20
62
63template<class charT, class traits>
64basic_ostream<charT, traits>&
65operator<<(basic_ostream<charT, traits>& out, thread::id id);
66
67template<class charT>
68struct formatter<thread::id, charT>;
69
70namespace this_thread
71{
72
73thread::id get_id() noexcept;
74
75void yield() noexcept;
76
77template <class Clock, class Duration>
78void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
79
80template <class Rep, class Period>
81void sleep_for(const chrono::duration<Rep, Period>& rel_time);
82
83}  // this_thread
84
85}  // std
86
87*/
88
89#include <__assert> // all public C++ headers provide the assertion handler
90#include <__availability>
91#include <__config>
92#include <__thread/formatter.h>
93#include <__thread/jthread.h>
94#include <__thread/this_thread.h>
95#include <__thread/thread.h>
96#include <__threading_support>
97#include <version>
98
99// standard-mandated includes
100
101// [thread.syn]
102#include <compare>
103
104#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
105#  pragma GCC system_header
106#endif
107
108#ifdef _LIBCPP_HAS_NO_THREADS
109#  error "<thread> is not supported since libc++ has been configured without support for threads."
110#endif
111
112#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
113#  include <cstddef>
114#  include <ctime>
115#  include <iosfwd>
116#  include <ratio>
117#endif
118
119#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
120#  include <chrono>
121#endif
122
123#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
124#  include <cstring>
125#  include <functional>
126#  include <new>
127#  include <system_error>
128#  include <type_traits>
129#endif
130
131#endif // _LIBCPP_THREAD
132