ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/LongMutex.java
(Generate patch)

Comparing jsr166/src/test/loops/LongMutex.java (file contents):
Revision 1.1 by dl, Mon May 2 19:19:38 2005 UTC vs.
Revision 1.4 by jsr166, Wed Dec 31 17:00:58 2014 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 + import java.io.*;
8   import java.util.*;
9   import java.util.concurrent.*;
9 import java.util.concurrent.locks.*;
10   import java.util.concurrent.atomic.*;
11 < import java.io.*;
11 > import java.util.concurrent.locks.*;
12  
13   /**
14 < * A sample user extension of AbstractQueuedLongSynchronizer.
14 > * A sample user extension of AbstractQueuedLongSynchronizer.
15   */
16   public final class LongMutex extends AbstractQueuedLongSynchronizer implements Lock, java.io.Serializable {
17      static final long LOCKED = -1L;
18      public boolean isHeldExclusively() { return getState() == LOCKED; }
19 <    
19 >
20      public boolean tryAcquire(long acquires) {
21          return compareAndSetState(0, LOCKED);
22      }
23 <    
23 >
24      public boolean tryRelease(long releases) {
25          setState(0);
26          return true;
27      }
28      public Condition newCondition() { return new ConditionObject(); }
29 <    
29 >
30      private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
31          s.defaultReadObject();
32          setState(0); // reset to unlocked state
33      }
34  
35 <    public void lock() {
36 <        acquire(LOCKED);  
35 >    public void lock() {
36 >        acquire(LOCKED);
37      }
38 <    public boolean tryLock() {
38 >    public boolean tryLock() {
39          return tryAcquire(LOCKED);
40      }
41 <    public void lockInterruptibly() throws InterruptedException {
41 >    public void lockInterruptibly() throws InterruptedException {
42          acquireInterruptibly(LOCKED);
43      }
44      public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines