32 |
|
private static class Sync extends AbstractQueuedSynchronizer { |
33 |
|
public int acquireExclusiveState(boolean isQueued, int acquires) { |
34 |
|
assert acquires == 1; // Does not use multiple acquires |
35 |
< |
return state().compareAndSet(0, 1)? 0 : -1; |
35 |
> |
return compareAndSet(0, 1)? 0 : -1; |
36 |
|
} |
37 |
|
|
38 |
|
public boolean releaseExclusiveState(int releases) { |
39 |
< |
state().set(0); |
39 |
> |
set(0); |
40 |
|
return true; |
41 |
|
} |
42 |
|
|
43 |
– |
public int acquireSharedState(boolean isQueued, int acquires) { |
44 |
– |
throw new UnsupportedOperationException(); |
45 |
– |
} |
46 |
– |
|
47 |
– |
public boolean releaseSharedState(int releases) { |
48 |
– |
throw new UnsupportedOperationException(); |
49 |
– |
} |
50 |
– |
|
43 |
|
public void checkConditionAccess(Thread thread, boolean waiting) { |
44 |
< |
if (state().get() == 0) throw new IllegalMonitorStateException(); |
44 |
> |
if (get() == 0) throw new IllegalMonitorStateException(); |
45 |
|
} |
46 |
|
|
47 |
|
Condition newCondition() { return new ConditionObject(); } |
48 |
|
|
49 |
|
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { |
50 |
|
s.defaultReadObject(); |
51 |
< |
state().set(0); // reset to unlocked state |
51 |
> |
set(0); // reset to unlocked state |
52 |
|
} |
53 |
|
} |
54 |
|
|
67 |
|
} |
68 |
|
public void unlock() { sync.releaseExclusive(1); } |
69 |
|
public Condition newCondition() { return sync.newCondition(); } |
70 |
< |
public boolean isLocked() { return sync.state().get() != 0; } |
70 |
> |
public boolean isLocked() { return sync.get() != 0; } |
71 |
|
public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); } |
72 |
|
} |
73 |
|
|