Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CancellationTokenRegistration.cs
Go to the documentation of this file.
3
4namespace System.Threading;
5
6public readonly struct CancellationTokenRegistration : IEquatable<CancellationTokenRegistration>, IDisposable, IAsyncDisposable
7{
8 private readonly long _id;
9
11
12 public CancellationToken Token
13 {
14 get
15 {
17 if (node == null)
18 {
19 return default(CancellationToken);
20 }
21 return new CancellationToken(node.Registrations.Source);
22 }
23 }
24
26 {
27 _id = id;
28 _node = node;
29 }
30
31 public void Dispose()
32 {
34 if (node2 != null && !node2.Registrations.Unregister(_id, node2))
35 {
36 WaitForCallbackIfNecessary(_id, node2);
37 }
38 static void WaitForCallbackIfNecessary(long id, CancellationTokenSource.CallbackNode node)
39 {
41 if (source.IsCancellationRequested && !source.IsCancellationCompleted && node.Registrations.ThreadIDExecutingCallbacks != Environment.CurrentManagedThreadId)
42 {
44 }
45 }
46 }
47
49 {
51 if (node2 == null || node2.Registrations.Unregister(_id, node2))
52 {
53 return default(ValueTask);
54 }
55 return WaitForCallbackIfNecessaryAsync(_id, node2);
56 static ValueTask WaitForCallbackIfNecessaryAsync(long id, CancellationTokenSource.CallbackNode node)
57 {
59 if (source.IsCancellationRequested && !source.IsCancellationCompleted && node.Registrations.ThreadIDExecutingCallbacks != Environment.CurrentManagedThreadId)
60 {
62 }
63 return default(ValueTask);
64 }
65 }
66
67 public bool Unregister()
68 {
70 return node?.Registrations.Unregister(_id, node) ?? false;
71 }
72
74 {
75 return left.Equals(right);
76 }
77
79 {
80 return !left.Equals(right);
81 }
82
83 public override bool Equals([NotNullWhen(true)] object? obj)
84 {
86 {
87 return Equals(other);
88 }
89 return false;
90 }
91
93 {
94 if (_node == other._node)
95 {
96 return _id == other._id;
97 }
98 return false;
99 }
100
101 public override int GetHashCode()
102 {
103 if (_node == null)
104 {
105 return _id.GetHashCode();
106 }
107 return _node.GetHashCode() ^ _id.GetHashCode();
108 }
109}
static int CurrentManagedThreadId
bool Equals(CancellationTokenRegistration other)
static bool operator!=(CancellationTokenRegistration left, CancellationTokenRegistration right)
override bool Equals([NotNullWhen(true)] object? obj)
CancellationTokenRegistration(long id, CancellationTokenSource.CallbackNode node)
static bool operator==(CancellationTokenRegistration left, CancellationTokenRegistration right)
readonly CancellationTokenSource.CallbackNode _node