Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StackGuard.cs
Go to the documentation of this file.
1
using
System.Runtime.CompilerServices
;
2
using
System.Threading
;
3
using
System.Threading.Tasks
;
4
5
namespace
System.Linq.Expressions
;
6
7
internal
sealed
class
StackGuard
8
{
9
private
int
_executionStackCount
;
10
11
public
bool
TryEnterOnCurrentStack
()
12
{
13
if
(
RuntimeHelpers
.
TryEnsureSufficientExecutionStack
())
14
{
15
return
true
;
16
}
17
if
(
_executionStackCount
< 1024)
18
{
19
return
false
;
20
}
21
throw
new
InsufficientExecutionStackException
();
22
}
23
24
public
void
RunOnEmptyStack<T1, T2>
(Action<T1, T2>
action
, T1 arg1, T2 arg2)
25
{
26
RunOnEmptyStackCore(delegate(
object
s
)
27
{
28
(Action<T1, T2>, T1, T2) tuple = ((Action<T1, T2>, T1, T2))
s
;
29
tuple.Item1(tuple.Item2, tuple.Item3);
30
return
(
object
)
null
;
31
}, (
action
, arg1, arg2));
32
}
33
34
public
void
RunOnEmptyStack<T1, T2, T3>
(Action<T1, T2, T3>
action
, T1 arg1, T2 arg2, T3 arg3)
35
{
36
RunOnEmptyStackCore(delegate(
object
s
)
37
{
38
(Action<T1, T2, T3>, T1, T2, T3) tuple = ((Action<T1, T2, T3>, T1, T2, T3))
s
;
39
tuple.Item1(tuple.Item2, tuple.Item3, tuple.Item4);
40
return
(
object
)
null
;
41
}, (
action
, arg1, arg2, arg3));
42
}
43
44
public
R
RunOnEmptyStack<T1, T2, R>
(Func<T1, T2, R>
action
, T1 arg1, T2 arg2)
45
{
46
return
RunOnEmptyStackCore(delegate(
object
s
)
47
{
48
(Func<T1, T2, R>, T1, T2) tuple = ((Func<T1, T2, R>, T1, T2))
s
;
49
return
tuple.Item1(tuple.Item2, tuple.Item3);
50
}, (
action
, arg1, arg2));
51
}
52
53
public
R
RunOnEmptyStack<T1, T2, T3, R>
(Func<T1, T2, T3, R>
action
, T1 arg1, T2 arg2, T3 arg3)
54
{
55
return
RunOnEmptyStackCore(delegate(
object
s
)
56
{
57
(Func<T1, T2, T3, R>, T1, T2, T3) tuple = ((Func<T1, T2, T3, R>, T1, T2, T3))
s
;
58
return
tuple.Item1(tuple.Item2, tuple.Item3, tuple.Item4);
59
}, (
action
, arg1, arg2, arg3));
60
}
61
62
private
R
RunOnEmptyStackCore<R>
(Func<object, R>
action
,
object
state
)
63
{
64
_executionStackCount
++;
65
try
66
{
67
Task<R>
task
=
Task
.
Factory
.StartNew(
action
,
state
,
CancellationToken
.
None
,
TaskCreationOptions
.DenyChildAttach,
TaskScheduler
.
Default
);
68
if
(!
task
.IsCompleted)
69
{
70
((
IAsyncResult
)
task
).AsyncWaitHandle.WaitOne();
71
}
72
return
task
.GetAwaiter().GetResult();
73
}
74
finally
75
{
76
_executionStackCount
--;
77
}
78
}
79
}
System.InsufficientExecutionStackException
Definition
InsufficientExecutionStackException.cs:9
System.Linq.Expressions.StackGuard._executionStackCount
int _executionStackCount
Definition
StackGuard.cs:9
System.Linq.Expressions.StackGuard.RunOnEmptyStack< T1, T2 >
void RunOnEmptyStack< T1, T2 >(Action< T1, T2 > action, T1 arg1, T2 arg2)
Definition
StackGuard.cs:24
System.Linq.Expressions.StackGuard.RunOnEmptyStackCore< R >
R RunOnEmptyStackCore< R >(Func< object, R > action, object state)
Definition
StackGuard.cs:62
System.Linq.Expressions.StackGuard.TryEnterOnCurrentStack
bool TryEnterOnCurrentStack()
Definition
StackGuard.cs:11
System.Linq.Expressions.StackGuard.RunOnEmptyStack< T1, T2, R >
R RunOnEmptyStack< T1, T2, R >(Func< T1, T2, R > action, T1 arg1, T2 arg2)
Definition
StackGuard.cs:44
System.Linq.Expressions.StackGuard.RunOnEmptyStack< T1, T2, T3 >
void RunOnEmptyStack< T1, T2, T3 >(Action< T1, T2, T3 > action, T1 arg1, T2 arg2, T3 arg3)
Definition
StackGuard.cs:34
System.Linq.Expressions.StackGuard.RunOnEmptyStack< T1, T2, T3, R >
R RunOnEmptyStack< T1, T2, T3, R >(Func< T1, T2, T3, R > action, T1 arg1, T2 arg2, T3 arg3)
Definition
StackGuard.cs:53
System.Linq.Expressions.StackGuard
Definition
StackGuard.cs:8
System.Runtime.CompilerServices.RuntimeHelpers.TryEnsureSufficientExecutionStack
static bool TryEnsureSufficientExecutionStack()
System.Runtime.CompilerServices.RuntimeHelpers
Definition
RuntimeHelpers.cs:12
System.Threading.Tasks.TaskScheduler.Default
static TaskScheduler Default
Definition
TaskScheduler.cs:71
System.Threading.Tasks.TaskScheduler
Definition
TaskScheduler.cs:10
System.Threading.Tasks.Task.Factory
static new TaskFactory< TResult > Factory
Definition
Task.cs:56
System.Threading.Tasks.Task
Definition
Task.cs:14
System.IAsyncResult
Definition
IAsyncResult.cs:6
System.Linq.Expressions
Definition
AnalyzedTree.cs:3
System.Runtime.CompilerServices
Definition
NullablePublicOnlyAttribute.cs:3
System.Threading.Tasks.TaskCreationOptions
TaskCreationOptions
Definition
TaskCreationOptions.cs:5
System.Threading.Tasks
Definition
TaskToApm.cs:3
System.Threading
Definition
TaskToApm.cs:3
System.ExceptionArgument.s
@ s
System.ExceptionArgument.action
@ action
System.ExceptionArgument.task
@ task
System.ExceptionArgument.state
@ state
System.ConsoleKey.R
@ R
System.Threading.CancellationToken.None
static CancellationToken None
Definition
CancellationToken.cs:11
System.Threading.CancellationToken
Definition
CancellationToken.cs:8
source
System.Linq.Expressions
System.Linq.Expressions
StackGuard.cs
Generated by
1.10.0