forked from lewissbaker/cppcoro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcancellation_token.hpp
More file actions
72 lines (52 loc) · 1.92 KB
/
cancellation_token.hpp
File metadata and controls
72 lines (52 loc) · 1.92 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
72
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Lewis Baker
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCORO_CANCELLATION_TOKEN_HPP_INCLUDED
#define CPPCORO_CANCELLATION_TOKEN_HPP_INCLUDED
namespace cppcoro
{
class cancellation_source;
class cancellation_registration;
namespace detail
{
class cancellation_state;
}
class cancellation_token
{
public:
/// Construct to a cancellation token that can't be cancelled.
cancellation_token() noexcept;
/// Copy another cancellation token.
///
/// New token will refer to the same underlying state.
cancellation_token(const cancellation_token& other) noexcept;
cancellation_token(cancellation_token&& other) noexcept;
~cancellation_token();
cancellation_token& operator=(const cancellation_token& other) noexcept;
cancellation_token& operator=(cancellation_token&& other) noexcept;
void swap(cancellation_token& other) noexcept;
/// Query if it is possible that this operation will be cancelled
/// or not.
///
/// Cancellable operations may be able to take more efficient code-paths
/// if they don't need to handle cancellation requests.
bool can_be_cancelled() const noexcept;
/// Query if some thread has requested cancellation on an associated
/// cancellation_source object.
bool is_cancellation_requested() const noexcept;
/// Throws cppcoro::operation_cancelled exception if cancellation
/// has been requested for the associated operation.
void throw_if_cancellation_requested() const;
private:
friend class cancellation_source;
friend class cancellation_registration;
cancellation_token(detail::cancellation_state* state) noexcept;
detail::cancellation_state* m_state;
};
inline void swap(cancellation_token& a, cancellation_token& b) noexcept
{
a.swap(b);
}
}
#endif