forked from andreasbuhr/cppcoro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcancellation_source.hpp
More file actions
71 lines (54 loc) · 2.12 KB
/
Copy pathcancellation_source.hpp
File metadata and controls
71 lines (54 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Lewis Baker
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCORO_CANCELLATION_SOURCE_HPP_INCLUDED
#define CPPCORO_CANCELLATION_SOURCE_HPP_INCLUDED
namespace cppcoro
{
class cancellation_token;
namespace detail
{
class cancellation_state;
}
class cancellation_source
{
public:
/// Construct to a new cancellation source.
cancellation_source();
/// Create a new reference to the same underlying cancellation
/// source as \p other.
cancellation_source(const cancellation_source& other) noexcept;
cancellation_source(cancellation_source&& other) noexcept;
~cancellation_source();
cancellation_source& operator=(const cancellation_source& other) noexcept;
cancellation_source& operator=(cancellation_source&& other) noexcept;
/// Query if this cancellation source can be cancelled.
///
/// A cancellation source object will not be cancellable if it has
/// previously been moved into another cancellation_source instance
/// or was copied from a cancellation_source that was not cancellable.
bool can_be_cancelled() const noexcept;
/// Obtain a cancellation token that can be used to query if
/// cancellation has been requested on this source.
///
/// The cancellation token can be passed into functions that you
/// may want to later be able to request cancellation.
cancellation_token token() const noexcept;
/// Request cancellation of operations that were passed an associated
/// cancellation token.
///
/// Any cancellation callback registered via a cancellation_registration
/// object will be called inside this function by the first thread to
/// call this method.
///
/// This operation is a no-op if can_be_cancelled() returns false.
void request_cancellation();
/// Query if some thread has called 'request_cancellation()' on this
/// cancellation_source.
bool is_cancellation_requested() const noexcept;
private:
detail::cancellation_state* m_state;
};
}
#endif