Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CheapUnfairReaderWriterLock.cs
Go to the documentation of this file.
2
3namespace System.Transactions;
4
5internal sealed class CheapUnfairReaderWriterLock
6{
7 private object _writerFinishedEvent;
8
9 private int _readersIn;
10
11 private int _readersOut;
12
13 private bool _writerPresent;
14
15 private object _syncRoot;
16
17 private object SyncRoot
18 {
19 get
20 {
21 if (_syncRoot == null)
22 {
23 Interlocked.CompareExchange(ref _syncRoot, new object(), null);
24 }
25 return _syncRoot;
26 }
27 }
28
30
32 {
33 get
34 {
35 if (_writerFinishedEvent == null)
36 {
37 Interlocked.CompareExchange(ref _writerFinishedEvent, new ManualResetEvent(initialState: true), null);
38 }
40 }
41 }
42
43 public int EnterReadLock()
44 {
45 int num = 0;
46 while (true)
47 {
49 {
51 }
53 if (!_writerPresent)
54 {
55 break;
56 }
58 }
59 return num;
60 }
61
62 public void EnterWriteLock()
63 {
65 _writerPresent = true;
67 do
68 {
69 int num = 0;
70 while (ReadersPresent && num < 100)
71 {
72 Thread.Sleep(0);
73 num++;
74 }
76 {
77 Thread.Sleep(500);
78 }
79 }
80 while (ReadersPresent);
81 }
82
83 public void ExitReadLock()
84 {
86 }
87
88 public void ExitWriteLock()
89 {
90 try
91 {
92 _writerPresent = false;
94 }
95 finally
96 {
98 }
99 }
100}
static int CompareExchange(ref int location1, int value, int comparand)
static int Decrement(ref int location)
static int Increment(ref int location)
static void Exit(object obj)
static void Enter(object obj)
static void Sleep(int millisecondsTimeout)
Definition Thread.cs:658
virtual bool WaitOne(int millisecondsTimeout)