[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / libcxx / include / __stop_token / stop_token.h
blobf2eadb990bdeca2f63620bcedc6defa4ed99c086
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___STOP_TOKEN_STOP_TOKEN_H
11 #define _LIBCPP___STOP_TOKEN_STOP_TOKEN_H
13 #include <__availability>
14 #include <__config>
15 #include <__stop_token/intrusive_shared_ptr.h>
16 #include <__stop_token/stop_state.h>
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 # pragma GCC system_header
20 #endif
22 _LIBCPP_BEGIN_NAMESPACE_STD
24 #if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && !defined(_LIBCPP_HAS_NO_THREADS)
26 class _LIBCPP_AVAILABILITY_SYNC stop_token {
27 public:
28 _LIBCPP_HIDE_FROM_ABI stop_token() noexcept = default;
30 _LIBCPP_HIDE_FROM_ABI stop_token(const stop_token&) noexcept = default;
31 _LIBCPP_HIDE_FROM_ABI stop_token(stop_token&&) noexcept = default;
32 _LIBCPP_HIDE_FROM_ABI stop_token& operator=(const stop_token&) noexcept = default;
33 _LIBCPP_HIDE_FROM_ABI stop_token& operator=(stop_token&&) noexcept = default;
34 _LIBCPP_HIDE_FROM_ABI ~stop_token() = default;
36 _LIBCPP_HIDE_FROM_ABI void swap(stop_token& __other) noexcept { __state_.swap(__other.__state_); }
38 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool stop_requested() const noexcept {
39 return __state_ != nullptr && __state_->__stop_requested();
42 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool stop_possible() const noexcept {
43 return __state_ != nullptr && __state_->__stop_possible_for_stop_token();
46 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend bool operator==(const stop_token&, const stop_token&) noexcept = default;
48 _LIBCPP_HIDE_FROM_ABI friend void swap(stop_token& __lhs, stop_token& __rhs) noexcept { __lhs.swap(__rhs); }
50 private:
51 __intrusive_shared_ptr<__stop_state> __state_;
53 friend class stop_source;
54 template <class _Tp>
55 friend class stop_callback;
57 _LIBCPP_HIDE_FROM_ABI explicit stop_token(const __intrusive_shared_ptr<__stop_state>& __state) : __state_(__state) {}
60 #endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && !defined(_LIBCPP_HAS_NO_THREADS)
62 _LIBCPP_END_NAMESPACE_STD
64 #endif // _LIBCPP___STOP_TOKEN_STOP_TOKEN_H