Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Bucket.cs
Go to the documentation of this file.
2
3namespace System.Transactions;
4
5internal sealed class Bucket
6{
7 private bool _timedOut;
8
9 private int _index;
10
11 private readonly int _size;
12
14
16
18
19 private readonly BucketSet _owningSet;
20
21 internal Bucket(BucketSet owningSet)
22 {
23 _timedOut = false;
24 _index = -1;
25 _size = 1024;
27 _owningSet = owningSet;
28 }
29
30 internal bool Add(InternalTransaction tx)
31 {
32 int num = Interlocked.Increment(ref _index);
33 if (num < _size)
34 {
35 tx._tableBucket = this;
36 tx._bucketIndex = num;
38 _transactions[num] = tx;
39 if (_timedOut)
40 {
41 lock (tx)
42 {
43 tx.State.Timeout(tx);
44 }
45 }
46 return true;
47 }
48 Bucket bucket = new Bucket(_owningSet);
49 bucket.nextBucketWeak = new WeakReference(this);
50 Bucket bucket2 = Interlocked.CompareExchange(ref _owningSet.headBucket, bucket, this);
51 if (bucket2 == this)
52 {
53 _previous = bucket;
54 }
55 return false;
56 }
57
58 internal void Remove(InternalTransaction tx)
59 {
60 _transactions[tx._bucketIndex] = null;
61 }
62
63 internal void TimeoutTransactions()
64 {
65 int index = _index;
66 _timedOut = true;
68 for (int i = 0; i <= index && i < _size; i++)
69 {
70 InternalTransaction internalTransaction = _transactions[i];
71 if (internalTransaction != null)
72 {
73 lock (internalTransaction)
74 {
75 internalTransaction.State.Timeout(internalTransaction);
76 }
77 }
78 }
79 }
80}
static int CompareExchange(ref int location1, int value, int comparand)
static int Increment(ref int location)
readonly BucketSet _owningSet
Definition Bucket.cs:19
bool Add(InternalTransaction tx)
Definition Bucket.cs:30
void Remove(InternalTransaction tx)
Definition Bucket.cs:58
Bucket(BucketSet owningSet)
Definition Bucket.cs:21
readonly InternalTransaction[] _transactions
Definition Bucket.cs:13
WeakReference nextBucketWeak
Definition Bucket.cs:15
virtual void Timeout(InternalTransaction tx)