Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SafeHandleCache.cs
Go to the documentation of this file.
1using System;
4
6
7internal static class SafeHandleCache<T> where T : SafeHandle
8{
9 private static T s_invalidHandle;
10
11 internal static T GetInvalidHandle(Func<T> invalidHandleFactory)
12 {
13 T val = Volatile.Read(ref s_invalidHandle);
14 if (val == null)
15 {
16 T val2 = invalidHandleFactory();
17 val = Interlocked.CompareExchange(ref s_invalidHandle, val2, null);
18 if (val == null)
19 {
20 GC.SuppressFinalize(val2);
21 val = val2;
22 }
23 else
24 {
25 val2.Dispose();
26 }
27 }
28 return val;
29 }
30
32 {
33 return handle == Volatile.Read(ref s_invalidHandle);
34 }
35}
static T GetInvalidHandle(Func< T > invalidHandleFactory)
static bool IsCachedInvalidHandle(SafeHandle handle)
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static int CompareExchange(ref int location1, int value, int comparand)
static bool Read(ref bool location)
Definition Volatile.cs:67