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_SOURCE_HPP_INCLUDED
0006 #define CPPCORO_CANCELLATION_SOURCE_HPP_INCLUDED
0007 
0008 namespace cppcoro
0009 {
0010     class cancellation_token;
0011 
0012     namespace detail
0013     {
0014         class cancellation_state;
0015     }
0016 
0017     class cancellation_source
0018     {
0019     public:
0020 
0021         /// Construct to a new cancellation source.
0022         cancellation_source();
0023 
0024         /// Create a new reference to the same underlying cancellation
0025         /// source as \p other.
0026         cancellation_source(const cancellation_source& other) noexcept;
0027 
0028         cancellation_source(cancellation_source&& other) noexcept;
0029 
0030         ~cancellation_source();
0031 
0032         cancellation_source& operator=(const cancellation_source& other) noexcept;
0033 
0034         cancellation_source& operator=(cancellation_source&& other) noexcept;
0035 
0036         /// Query if this cancellation source can be cancelled.
0037         ///
0038         /// A cancellation source object will not be cancellable if it has
0039         /// previously been moved into another cancellation_source instance
0040         /// or was copied from a cancellation_source that was not cancellable.
0041         bool can_be_cancelled() const noexcept;
0042 
0043         /// Obtain a cancellation token that can be used to query if
0044         /// cancellation has been requested on this source.
0045         ///
0046         /// The cancellation token can be passed into functions that you
0047         /// may want to later be able to request cancellation.
0048         cancellation_token token() const noexcept;
0049 
0050         /// Request cancellation of operations that were passed an associated
0051         /// cancellation token.
0052         ///
0053         /// Any cancellation callback registered via a cancellation_registration
0054         /// object will be called inside this function by the first thread to
0055         /// call this method.
0056         ///
0057         /// This operation is a no-op if can_be_cancelled() returns false.
0058         void request_cancellation();
0059 
0060         /// Query if some thread has called 'request_cancellation()' on this
0061         /// cancellation_source.
0062         bool is_cancellation_requested() const noexcept;
0063 
0064     private:
0065 
0066         detail::cancellation_state* m_state;
0067 
0068     };
0069 }
0070 
0071 #endif