xref: /freebsd/contrib/llvm-project/libcxx/include/__stop_token/stop_token.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
106c3fb27SDimitry Andric // -*- C++ -*-
206c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
306c3fb27SDimitry Andric //
406c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
506c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
606c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
706c3fb27SDimitry Andric //
806c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
906c3fb27SDimitry Andric 
1006c3fb27SDimitry Andric #ifndef _LIBCPP___STOP_TOKEN_STOP_TOKEN_H
1106c3fb27SDimitry Andric #define _LIBCPP___STOP_TOKEN_STOP_TOKEN_H
1206c3fb27SDimitry Andric 
1306c3fb27SDimitry Andric #include <__config>
1406c3fb27SDimitry Andric #include <__stop_token/intrusive_shared_ptr.h>
1506c3fb27SDimitry Andric #include <__stop_token/stop_state.h>
1606c3fb27SDimitry Andric 
1706c3fb27SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1806c3fb27SDimitry Andric #  pragma GCC system_header
1906c3fb27SDimitry Andric #endif
2006c3fb27SDimitry Andric 
2106c3fb27SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
2206c3fb27SDimitry Andric 
23*5f757f3fSDimitry Andric #if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && !defined(_LIBCPP_HAS_NO_THREADS)
2406c3fb27SDimitry Andric 
2506c3fb27SDimitry Andric class _LIBCPP_AVAILABILITY_SYNC stop_token {
2606c3fb27SDimitry Andric public:
2706c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI stop_token() noexcept = default;
2806c3fb27SDimitry Andric 
2906c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI stop_token(const stop_token&) noexcept            = default;
3006c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI stop_token(stop_token&&) noexcept                 = default;
3106c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI stop_token& operator=(const stop_token&) noexcept = default;
3206c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI stop_token& operator=(stop_token&&) noexcept      = default;
3306c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI ~stop_token()                                     = default;
3406c3fb27SDimitry Andric 
swap(stop_token & __other)3506c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI void swap(stop_token& __other) noexcept { __state_.swap(__other.__state_); }
3606c3fb27SDimitry Andric 
stop_requested()3706c3fb27SDimitry Andric   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool stop_requested() const noexcept {
3806c3fb27SDimitry Andric     return __state_ != nullptr && __state_->__stop_requested();
3906c3fb27SDimitry Andric   }
4006c3fb27SDimitry Andric 
stop_possible()4106c3fb27SDimitry Andric   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool stop_possible() const noexcept {
4206c3fb27SDimitry Andric     return __state_ != nullptr && __state_->__stop_possible_for_stop_token();
4306c3fb27SDimitry Andric   }
4406c3fb27SDimitry Andric 
4506c3fb27SDimitry Andric   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend bool operator==(const stop_token&, const stop_token&) noexcept = default;
4606c3fb27SDimitry Andric 
swap(stop_token & __lhs,stop_token & __rhs)4706c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI friend void swap(stop_token& __lhs, stop_token& __rhs) noexcept { __lhs.swap(__rhs); }
4806c3fb27SDimitry Andric 
4906c3fb27SDimitry Andric private:
5006c3fb27SDimitry Andric   __intrusive_shared_ptr<__stop_state> __state_;
5106c3fb27SDimitry Andric 
5206c3fb27SDimitry Andric   friend class stop_source;
5306c3fb27SDimitry Andric   template <class _Tp>
5406c3fb27SDimitry Andric   friend class stop_callback;
5506c3fb27SDimitry Andric 
stop_token(const __intrusive_shared_ptr<__stop_state> & __state)5606c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI explicit stop_token(const __intrusive_shared_ptr<__stop_state>& __state) : __state_(__state) {}
5706c3fb27SDimitry Andric };
5806c3fb27SDimitry Andric 
59*5f757f3fSDimitry Andric #endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && !defined(_LIBCPP_HAS_NO_THREADS)
6006c3fb27SDimitry Andric 
6106c3fb27SDimitry Andric _LIBCPP_END_NAMESPACE_STD
6206c3fb27SDimitry Andric 
6306c3fb27SDimitry Andric #endif // _LIBCPP___STOP_TOKEN_STOP_TOKEN_H
64