Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:51

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // Copyright (c) Lewis Baker
0003 // Licenced under MIT license. See LICENSE.txt for details.
0004 ///////////////////////////////////////////////////////////////////////////////
0005 #ifndef CPPCORO_CANCELLATION_TOKEN_HPP_INCLUDED
0006 #define CPPCORO_CANCELLATION_TOKEN_HPP_INCLUDED
0007 
0008 namespace cppcoro
0009 {
0010     class cancellation_source;
0011     class cancellation_registration;
0012 
0013     namespace detail
0014     {
0015         class cancellation_state;
0016     }
0017 
0018     class cancellation_token
0019     {
0020     public:
0021 
0022         /// Construct to a cancellation token that can't be cancelled.
0023         cancellation_token() noexcept;
0024 
0025         /// Copy another cancellation token.
0026         ///
0027         /// New token will refer to the same underlying state.
0028         cancellation_token(const cancellation_token& other) noexcept;
0029 
0030         cancellation_token(cancellation_token&& other) noexcept;
0031 
0032         ~cancellation_token();
0033 
0034         cancellation_token& operator=(const cancellation_token& other) noexcept;
0035 
0036         cancellation_token& operator=(cancellation_token&& other) noexcept;
0037 
0038         void swap(cancellation_token& other) noexcept;
0039 
0040         /// Query if it is possible that this operation will be cancelled
0041         /// or not.
0042         ///
0043         /// Cancellable operations may be able to take more efficient code-paths
0044         /// if they don't need to handle cancellation requests.
0045         bool can_be_cancelled() const noexcept;
0046 
0047         /// Query if some thread has requested cancellation on an associated
0048         /// cancellation_source object.
0049         bool is_cancellation_requested() const noexcept;
0050 
0051         /// Throws cppcoro::operation_cancelled exception if cancellation
0052         /// has been requested for the associated operation.
0053         void throw_if_cancellation_requested() const;
0054 
0055     private:
0056 
0057         friend class cancellation_source;
0058         friend class cancellation_registration;
0059 
0060         cancellation_token(detail::cancellation_state* state) noexcept;
0061 
0062         detail::cancellation_state* m_state;
0063 
0064     };
0065 
0066     inline void swap(cancellation_token& a, cancellation_token& b) noexcept
0067     {
0068         a.swap(b);
0069     }
0070 }
0071 
0072 #endif