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

Comparing jsr166/src/jsr166e/SequenceLock.java (file contents):
Revision 1.2 by dl, Fri Jul 15 15:04:14 2011 UTC vs.
Revision 1.3 by dl, Fri Jul 15 15:44:48 2011 UTC

# Line 31 | Line 31 | import java.io.IOException;
31   * possibly platform-specific, value is used.
32   *
33   * <p>Except for the lack of support for specified fairness policies,
34 < * or {link Condition} objects, a SequenceLock can be used in the same
34 > * or {@link Condition} objects, a SequenceLock can be used in the same
35   * way as {@link ReentrantLock}, and has a nearly identical
36   * API. SequenceLocks may be preferable in contexts in which multiple
37   * threads invoke read-only methods much more frequently than fully
38   * locked methods.
39 < *
39 > *
40   * <p> Methods {@code awaitAvailability} and {@code getSequence} can
41   * be used together to define (partially) optimistic read-only methods
42   * that are usually more efficient than ReadWriteLocks when they
# Line 121 | Line 121 | public class SequenceLock implements Loc
121              return (getState() & 1L) != 0L &&
122                  getExclusiveOwnerThread() == Thread.currentThread();
123          }
124 <        
124 >
125        public final boolean tryAcquire(long acquires) {
126              Thread current = Thread.currentThread();
127              long c = getState();
# Line 138 | Line 138 | public class SequenceLock implements Loc
138              }
139              return false;
140          }
141 <        
141 >
142          public final boolean tryRelease(long releases) {
143              if (Thread.currentThread() != getExclusiveOwnerThread())
144                  throw new IllegalMonitorStateException();
# Line 151 | Line 151 | public class SequenceLock implements Loc
151          }
152  
153          public final long tryAcquireShared(long unused) {
154 <            return ((getState() & 1L) == 0L ||
155 <                    getExclusiveOwnerThread() == Thread.currentThread())?
154 >            return ((getState() & 1L) == 0L ||
155 >                    getExclusiveOwnerThread() == Thread.currentThread())?
156                  1L : -1L; // must return long
157          }
158  
# Line 160 | Line 160 | public class SequenceLock implements Loc
160              return true;
161          }
162  
163 <        public final Condition newCondition() {
163 >        public final Condition newCondition() {
164              throw new UnsupportedOperationException();
165          }
166  
# Line 169 | Line 169 | public class SequenceLock implements Loc
169          final long getSequence() {
170              return getState();
171          }
172 <        
172 >
173          final void lock() {
174              int k = spins;
175              while (!tryAcquire(1)) {
# Line 180 | Line 180 | public class SequenceLock implements Loc
180                  --k;
181              }
182          }
183 <        
183 >
184          final long awaitAvailability() {
185              long s;
186              int k = spins;
# Line 218 | Line 218 | public class SequenceLock implements Loc
218  
219      private final Sync sync;
220  
221 <    /**
221 >    /**
222       * The default spin value for constructor. Future versions of this
223       * class might choose platform-specific values.  Currently, except
224       * on uniprocessors, it is set to a small value that ovecomes near
225       * misses between releases and acquires.
226       */
227 <    static final int DEFAULT_SPINS =
227 >    static final int DEFAULT_SPINS =
228          Runtime.getRuntime().availableProcessors() > 1 ? 64 : 0;
229  
230      /**
# Line 236 | Line 236 | public class SequenceLock implements Loc
236  
237      /**
238       * Creates an instance of {@code SequenceLock} that
239 <     * will retry attempts to lock or await release
239 >     * will retry attempts to lock or await release
240       * at least the given number times before blocking.
241       */
242      public SequenceLock(int spins) { sync = new Sync(spins); }
# Line 261 | Line 261 | public class SequenceLock implements Loc
261       * @return the current sequence number
262       */
263      public long awaitAvailability() { return sync.awaitAvailability(); }
264 <    
264 >
265      /**
266       * Acquires the lock.
267       *
# Line 334 | Line 334 | public class SequenceLock implements Loc
334       *
335       * <p>Acquires the lock if it is not held by another thread and
336       * returns immediately with the value {@code true}, setting the
337 <     * lock hold count to one.
337 >     * lock hold count to one.
338       *
339       * <p> If the current thread already holds this lock then the hold
340       * count is incremented by one and the method returns {@code true}.
# Line 445 | Line 445 | public class SequenceLock implements Loc
445       *
446       * @throws UnsupportedOperationException
447       */
448 <    public Condition newCondition()   {
448 >    public Condition newCondition()   {
449          throw new UnsupportedOperationException();
450      }
451  
# Line 456 | Line 456 | public class SequenceLock implements Loc
456       * matched by an unlock action.
457       *
458       * <p>The hold count information is typically only used for testing and
459 <     * debugging purposes.
459 >     * debugging purposes.
460       *
461       * @return the number of holds on this lock by the current thread,
462       *         or zero if this lock is not held by the current thread
# Line 570 | Line 570 | public class SequenceLock implements Loc
570      }
571  
572   }
573 <            
573 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines