ICURWLock.java
4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.impl;
public class ICURWLock {
private Object writeLock = new Object();
private Object readLock = new Object();
private int wwc;
private int rc;
private int wrc;
private Stats stats = new Stats();
private synchronized boolean gotRead() {
++this.rc;
if (this.stats != null) {
++this.stats._rc;
if (this.rc > 1) {
++this.stats._mrc;
}
}
return true;
}
private synchronized boolean getRead() {
if (this.rc >= 0 && this.wwc == 0) {
return this.gotRead();
}
++this.wrc;
return false;
}
private synchronized boolean retryRead() {
if (this.stats != null) {
++this.stats._wrc;
}
if (this.rc >= 0 && this.wwc == 0) {
--this.wrc;
return this.gotRead();
}
return false;
}
private synchronized boolean finishRead() {
if (this.rc > 0) {
return 0 == --this.rc && this.wwc > 0;
}
throw new IllegalStateException("no current reader to release");
}
private synchronized boolean gotWrite() {
this.rc = -1;
if (this.stats != null) {
++this.stats._wc;
}
return true;
}
private synchronized boolean getWrite() {
if (this.rc == 0) {
return this.gotWrite();
}
++this.wwc;
return false;
}
private synchronized boolean retryWrite() {
if (this.stats != null) {
++this.stats._wwc;
}
if (this.rc == 0) {
--this.wwc;
return this.gotWrite();
}
return false;
}
private synchronized int finishWrite() {
if (this.rc < 0) {
this.rc = 0;
if (this.wwc > 0) {
return 1;
}
if (this.wrc > 0) {
return 2;
}
return 0;
}
throw new IllegalStateException("no current writer to release");
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void acquireRead() {
if (!this.getRead()) {
do {
try {
do {
Object object = this.readLock;
synchronized (object) {
this.readLock.wait();
continue;
}
} while (!this.retryRead());
return;
}
catch (InterruptedException e) {
continue;
}
break;
} while (true);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void releaseRead() {
if (this.finishRead()) {
Object object = this.writeLock;
synchronized (object) {
this.writeLock.notify();
}
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void acquireWrite() {
if (!this.getWrite()) {
do {
try {
do {
Object object = this.writeLock;
synchronized (object) {
this.writeLock.wait();
continue;
}
} while (!this.retryWrite());
return;
}
catch (InterruptedException e) {
continue;
}
break;
} while (true);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void releaseWrite() {
switch (this.finishWrite()) {
case 1: {
Object object = this.writeLock;
synchronized (object) {
this.writeLock.notify();
break;
}
}
case 2: {
Object object = this.readLock;
synchronized (object) {
this.readLock.notifyAll();
break;
}
}
}
}
public static final class Stats {
public int _rc;
public int _mrc;
public int _wrc;
public int _wc;
public int _wwc;
private Stats() {
}
public String toString() {
return " rc: " + this._rc + " mrc: " + this._mrc + " wrc: " + this._wrc + " wc: " + this._wc + " wwc: " + this._wwc;
}
}
}