thread 3.2 KB

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