92 |
|
/** |
93 |
|
* Implements AQS base acquire to succeed if not in WAITING state |
94 |
|
*/ |
95 |
< |
public int acquireExclusiveState(boolean b, int ignore) { |
96 |
< |
return get() == WAITING ? -1 : 0; |
95 |
> |
public boolean tryAcquireExclusiveState(boolean b, int ignore) { |
96 |
> |
return getState() != WAITING; |
97 |
|
} |
98 |
|
|
99 |
|
/** |
100 |
|
* Implements AQS base release to always signal. |
101 |
|
* Status is changed in ack or cancel methods before calling, |
102 |
< |
* which is needed to ensure we win cancel race. |
102 |
> |
* which is needed to handle cancellation races. |
103 |
|
*/ |
104 |
|
public boolean releaseExclusiveState(int ignore) { |
105 |
|
return true; |
109 |
|
* Try to acknowledge; fail if not waiting |
110 |
|
*/ |
111 |
|
private boolean ack() { |
112 |
< |
if (!compareAndSet(WAITING, ACKED)) |
112 |
> |
if (!compareAndSetState(WAITING, ACKED)) |
113 |
|
return false; |
114 |
|
releaseExclusive(0); |
115 |
|
return true; |
119 |
|
* Try to cancel; fail if not waiting |
120 |
|
*/ |
121 |
|
private boolean cancel() { |
122 |
< |
if (!compareAndSet(WAITING, CANCELLED)) |
122 |
> |
if (!compareAndSetState(WAITING, CANCELLED)) |
123 |
|
return false; |
124 |
|
releaseExclusive(0); |
125 |
|
return true; |