Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SecureObjectPool.cs
Go to the documentation of this file.
2
4
5internal 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 {
17 }
18 while (num == -1);
19 return num;
20 }
21}
22internal 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;
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}
void TryAdd(TCaller caller, SecurePooledObject< T > item)
bool TryTake(TCaller caller, out SecurePooledObject< T >? item)
SecurePooledObject< T > PrepNew(TCaller caller, T newValue)
static int Increment(ref int location)