95 |
|
/** |
96 |
|
* Implements AQS base acquire to succeed if not in WAITING state |
97 |
|
*/ |
98 |
< |
protected boolean tryAcquireExclusive(int ignore) { |
98 |
> |
protected boolean tryAcquire(int ignore) { |
99 |
|
return getState() != 0; |
100 |
|
} |
101 |
|
|
102 |
|
/** |
103 |
|
* Implements AQS base release to signal if state changed |
104 |
|
*/ |
105 |
< |
protected boolean tryReleaseExclusive(int newState) { |
105 |
> |
protected boolean tryRelease(int newState) { |
106 |
|
return compareAndSetState(0, newState); |
107 |
|
} |
108 |
|
|
121 |
|
*/ |
122 |
|
private void checkCancellationOnInterrupt(InterruptedException ie) |
123 |
|
throws InterruptedException { |
124 |
< |
if (releaseExclusive(CANCEL)) |
124 |
> |
if (release(CANCEL)) |
125 |
|
throw ie; |
126 |
|
Thread.currentThread().interrupt(); |
127 |
|
} |
132 |
|
*/ |
133 |
|
boolean setItem(Object x) { |
134 |
|
item = x; // can place in slot even if cancelled |
135 |
< |
return releaseExclusive(ACK); |
135 |
> |
return release(ACK); |
136 |
|
} |
137 |
|
|
138 |
|
/** |
140 |
|
* to continue. |
141 |
|
*/ |
142 |
|
Object getItem() { |
143 |
< |
return (releaseExclusive(ACK))? extract() : null; |
143 |
> |
return (release(ACK))? extract() : null; |
144 |
|
} |
145 |
|
|
146 |
|
/** |
148 |
|
*/ |
149 |
|
void waitForTake() throws InterruptedException { |
150 |
|
try { |
151 |
< |
acquireExclusiveInterruptibly(0); |
151 |
> |
acquireInterruptibly(0); |
152 |
|
} catch (InterruptedException ie) { |
153 |
|
checkCancellationOnInterrupt(ie); |
154 |
|
} |
159 |
|
*/ |
160 |
|
Object waitForPut() throws InterruptedException { |
161 |
|
try { |
162 |
< |
acquireExclusiveInterruptibly(0); |
162 |
> |
acquireInterruptibly(0); |
163 |
|
} catch (InterruptedException ie) { |
164 |
|
checkCancellationOnInterrupt(ie); |
165 |
|
} |
171 |
|
*/ |
172 |
|
boolean waitForTake(long nanos) throws InterruptedException { |
173 |
|
try { |
174 |
< |
if (!acquireExclusiveNanos(0, nanos) && |
175 |
< |
releaseExclusive(CANCEL)) |
174 |
> |
if (!tryAcquireNanos(0, nanos) && |
175 |
> |
release(CANCEL)) |
176 |
|
return false; |
177 |
|
} catch (InterruptedException ie) { |
178 |
|
checkCancellationOnInterrupt(ie); |
185 |
|
*/ |
186 |
|
Object waitForPut(long nanos) throws InterruptedException { |
187 |
|
try { |
188 |
< |
if (!acquireExclusiveNanos(0, nanos) && |
189 |
< |
releaseExclusive(CANCEL)) |
188 |
> |
if (!tryAcquireNanos(0, nanos) && |
189 |
> |
release(CANCEL)) |
190 |
|
return null; |
191 |
|
} catch (InterruptedException ie) { |
192 |
|
checkCancellationOnInterrupt(ie); |