Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AllocFreeConcurrentStack.cs
Go to the documentation of this file.
1
using
System.Collections.Generic
;
2
using
System.Diagnostics.CodeAnalysis
;
3
4
namespace
System.Collections.Immutable
;
5
6
internal
static
class
AllocFreeConcurrentStack
<T>
7
{
8
private
static
readonly
Type
s_typeOfT
=
typeof
(T);
9
10
private
static
Stack<RefAsValueType<T>
>
ThreadLocalStack
11
{
12
get
13
{
14
Dictionary<Type, object>
dictionary
=
AllocFreeConcurrentStack
.
t_stacks
;
15
if
(
dictionary
==
null
)
16
{
17
dictionary
= (AllocFreeConcurrentStack.t_stacks =
new
Dictionary<Type, object>
());
18
}
19
if
(!
dictionary
.TryGetValue(
s_typeOfT
,
out
var
value
))
20
{
21
value
=
new
Stack<RefAsValueType<T>
>(35);
22
dictionary
.
Add
(
s_typeOfT
,
value
);
23
}
24
return
(
Stack
<
RefAsValueType<T>
>)
value
;
25
}
26
}
27
28
public
static
void
TryAdd
(T
item
)
29
{
30
Stack<RefAsValueType<T>
>
threadLocalStack
=
ThreadLocalStack
;
31
if
(
threadLocalStack
.
Count
< 35)
32
{
33
threadLocalStack
.Push(
new
RefAsValueType<T>
(
item
));
34
}
35
}
36
37
public
static
bool
TryTake
([
MaybeNullWhen
(
false
)]
out
T
item
)
38
{
39
Stack<RefAsValueType<T>
>
threadLocalStack
=
ThreadLocalStack
;
40
if
(
threadLocalStack
!=
null
&&
threadLocalStack
.
Count
> 0)
41
{
42
item
=
threadLocalStack
.Pop().Value;
43
return
true
;
44
}
45
item
=
default
(T);
46
return
false
;
47
}
48
}
49
internal
static
class
AllocFreeConcurrentStack
50
{
51
[
ThreadStatic
]
52
internal
static
Dictionary<Type, object>
?
t_stacks
;
53
}
System.Collections.Generic.Dictionary.Count
int Count
Definition
Dictionary.cs:682
System.Collections.Generic.Dictionary.Add
void Add(TKey key, TValue value)
Definition
Dictionary.cs:873
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Collections.Immutable.AllocFreeConcurrentStack.s_typeOfT
static readonly Type s_typeOfT
Definition
AllocFreeConcurrentStack.cs:8
System.Collections.Immutable.AllocFreeConcurrentStack.t_stacks
static ? Dictionary< Type, object > t_stacks
Definition
AllocFreeConcurrentStack.cs:52
System.Collections.Immutable.AllocFreeConcurrentStack.ThreadLocalStack
static Stack< RefAsValueType< T > > ThreadLocalStack
Definition
AllocFreeConcurrentStack.cs:11
System.Collections.Immutable.AllocFreeConcurrentStack.TryAdd
static void TryAdd(T item)
Definition
AllocFreeConcurrentStack.cs:28
System.Collections.Immutable.AllocFreeConcurrentStack.TryTake
static bool TryTake([MaybeNullWhen(false)] out T item)
Definition
AllocFreeConcurrentStack.cs:37
System.Collections.Immutable.AllocFreeConcurrentStack
Definition
AllocFreeConcurrentStack.cs:7
System.Collections.Stack
Definition
Stack.cs:11
System.Type
Definition
Type.cs:14
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Collections.Immutable
Definition
AllocFreeConcurrentStack.cs:4
System.Diagnostics.CodeAnalysis
Definition
AllowNullAttribute.cs:1
System.ExceptionArgument.value
@ value
System.ExceptionArgument.item
@ item
System.ExceptionArgument.dictionary
@ dictionary
source
System.Collections.Immutable
System.Collections.Immutable
AllocFreeConcurrentStack.cs
Generated by
1.10.0