29 |
|
} |
30 |
|
|
31 |
|
static final Mutex100M.Mutex lock = new Mutex100M.Mutex(); |
32 |
< |
|
32 |
> |
|
33 |
|
static int loop(int x, int iters) { |
34 |
|
final Mutex100M.Mutex l = lock; |
35 |
|
for (int i = iters; i > 0; --i) { |
43 |
|
|
44 |
|
static final class Mutex extends AbstractQueuedSynchronizer { |
45 |
|
public boolean isHeldExclusively() { return getState() == 1; } |
46 |
< |
|
46 |
> |
|
47 |
|
public boolean tryAcquire(int acquires) { |
48 |
|
return getState() == 0 && compareAndSetState(0, 1); |
49 |
|
} |
50 |
< |
|
50 |
> |
|
51 |
|
public boolean tryRelease(int releases) { |
52 |
|
setState(0); |
53 |
|
return true; |
54 |
|
} |
55 |
|
public Condition newCondition() { return new ConditionObject(); } |
56 |
< |
|
57 |
< |
public void lock() { |
56 |
> |
|
57 |
> |
public void lock() { |
58 |
|
if (!compareAndSetState(0, 1)) |
59 |
< |
acquire(1); |
59 |
> |
acquire(1); |
60 |
|
} |
61 |
< |
public boolean tryLock() { |
61 |
> |
public boolean tryLock() { |
62 |
|
return tryAcquire(1); |
63 |
|
} |
64 |
< |
public void lockInterruptibly() throws InterruptedException { |
64 |
> |
public void lockInterruptibly() throws InterruptedException { |
65 |
|
acquireInterruptibly(1); |
66 |
|
} |
67 |
|
public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException { |
69 |
|
} |
70 |
|
public void unlock() { release(1); } |
71 |
|
} |
72 |
< |
|
72 |
> |
|
73 |
|
} |