Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Disposables.cs
Go to the documentation of this file.
2
4
5internal sealed class Disposables
6{
7 [DebuggerDisplay("Disposed = true")]
8 private sealed class NopDisposable : IDisposable
9 {
11 {
12 }
13 }
14
15 [DebuggerDisplay("Disposed = {Disposed}")]
16 private sealed class Disposable<T1, T2> : IDisposable
17 {
18 private readonly T1 _arg1;
19
20 private readonly T2 _arg2;
21
22 private Action<T1, T2> _action;
23
24 private bool Disposed => _action == null;
25
26 internal Disposable(Action<T1, T2> action, T1 arg1, T2 arg2)
27 {
29 _arg1 = arg1;
30 _arg2 = arg2;
31 }
32
34 {
35 Action<T1, T2> action = _action;
36 if (action != null && Interlocked.CompareExchange(ref _action, null, action) == action)
37 {
39 }
40 }
41 }
42
43 [DebuggerDisplay("Disposed = {Disposed}")]
44 private sealed class Disposable<T1, T2, T3> : IDisposable
45 {
46 private readonly T1 _arg1;
47
48 private readonly T2 _arg2;
49
50 private readonly T3 _arg3;
51
52 private Action<T1, T2, T3> _action;
53
54 private bool Disposed => _action == null;
55
56 internal Disposable(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3)
57 {
59 _arg1 = arg1;
60 _arg2 = arg2;
61 _arg3 = arg3;
62 }
63
65 {
66 Action<T1, T2, T3> action = _action;
67 if (action != null && Interlocked.CompareExchange(ref _action, null, action) == action)
68 {
70 }
71 }
72 }
73
74 internal static readonly IDisposable Nop = new NopDisposable();
75
76 internal static IDisposable Create<T1, T2>(Action<T1, T2> action, T1 arg1, T2 arg2)
77 {
78 return new Disposable<T1, T2>(action, arg1, arg2);
79 }
80
81 internal static IDisposable Create<T1, T2, T3>(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3)
82 {
83 return new Disposable<T1, T2, T3>(action, arg1, arg2, arg3);
84 }
85}
static int CompareExchange(ref int location1, int value, int comparand)
Disposable(Action< T1, T2, T3 > action, T1 arg1, T2 arg2, T3 arg3)
Disposable(Action< T1, T2 > action, T1 arg1, T2 arg2)
static IDisposable Create< T1, T2 >(Action< T1, T2 > action, T1 arg1, T2 arg2)
static IDisposable Create< T1, T2, T3 >(Action< T1, T2, T3 > action, T1 arg1, T2 arg2, T3 arg3)