Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SecureObjectPool.cs
Go to the documentation of this file.
1
using
System.Threading
;
2
3
namespace
System.Collections.Immutable
;
4
5
internal
static
class
SecureObjectPool
6
{
7
private
static
int
s_poolUserIdCounter
;
8
9
internal
const
int
UnassignedId
= -1;
10
11
internal
static
int
NewId
()
12
{
13
int
num;
14
do
15
{
16
num =
Interlocked
.
Increment
(ref
s_poolUserIdCounter
);
17
}
18
while
(num == -1);
19
return
num;
20
}
21
}
22
internal
sealed
class
SecureObjectPool
<T, TCaller> where TCaller :
ISecurePooledObjectUser
23
{
24
public
void
TryAdd
(TCaller caller,
SecurePooledObject<T>
item
)
25
{
26
if
(caller.PoolUserId ==
item
.Owner)
27
{
28
item.Owner = -1;
29
AllocFreeConcurrentStack<SecurePooledObject<T>
>.
TryAdd
(
item
);
30
}
31
}
32
33
public
bool
TryTake
(TCaller caller, out
SecurePooledObject<T>
?
item
)
34
{
35
if
(caller.PoolUserId != -1 &&
AllocFreeConcurrentStack
<
SecurePooledObject<T>
>.TryTake(out
item
))
36
{
37
item.Owner = caller.PoolUserId;
38
return
true
;
39
}
40
item
=
null
;
41
return
false
;
42
}
43
44
public
SecurePooledObject<T>
PrepNew
(TCaller caller, T newValue)
45
{
46
Requires
.NotNullAllowStructs(newValue,
"newValue"
);
47
SecurePooledObject<T>
securePooledObject =
new
SecurePooledObject<T>
(newValue);
48
securePooledObject.Owner = caller.PoolUserId;
49
return
securePooledObject;
50
}
51
}
System.Collections.Immutable.AllocFreeConcurrentStack.TryAdd
static void TryAdd(T item)
Definition
AllocFreeConcurrentStack.cs:28
System.Collections.Immutable.AllocFreeConcurrentStack
Definition
AllocFreeConcurrentStack.cs:7
System.Collections.Immutable.Requires
Definition
Requires.cs:7
System.Collections.Immutable.SecureObjectPool.NewId
static int NewId()
Definition
SecureObjectPool.cs:11
System.Collections.Immutable.SecureObjectPool.TryAdd
void TryAdd(TCaller caller, SecurePooledObject< T > item)
Definition
SecureObjectPool.cs:24
System.Collections.Immutable.SecureObjectPool.UnassignedId
const int UnassignedId
Definition
SecureObjectPool.cs:9
System.Collections.Immutable.SecureObjectPool.s_poolUserIdCounter
static int s_poolUserIdCounter
Definition
SecureObjectPool.cs:7
System.Collections.Immutable.SecureObjectPool.TryTake
bool TryTake(TCaller caller, out SecurePooledObject< T >? item)
Definition
SecureObjectPool.cs:33
System.Collections.Immutable.SecureObjectPool.PrepNew
SecurePooledObject< T > PrepNew(TCaller caller, T newValue)
Definition
SecureObjectPool.cs:44
System.Collections.Immutable.SecureObjectPool
Definition
SecureObjectPool.cs:23
System.Collections.Immutable.SecurePooledObject
Definition
SecurePooledObject.cs:7
System.Threading.Interlocked.Increment
static int Increment(ref int location)
Definition
Interlocked.cs:10
System.Threading.Interlocked
Definition
Interlocked.cs:9
System.Collections.Immutable.ISecurePooledObjectUser
Definition
ISecurePooledObjectUser.cs:4
System.Collections.Immutable
Definition
AllocFreeConcurrentStack.cs:4
System.Threading
Definition
TaskToApm.cs:3
System.ExceptionArgument.item
@ item
source
System.Collections.Immutable
System.Collections.Immutable
SecureObjectPool.cs
Generated by
1.10.0