[jboss-cvs] JBossCache/src/org/jboss/cache/lock ...

Manik Surtani manik at jboss.org
Tue Jun 19 09:05:18 EDT 2007


  User: msurtani
  Date: 07/06/19 09:05:18

  Modified:    src/org/jboss/cache/lock  StripedLock.java
  Log:
  CL thread safety
  
  Revision  Changes    Path
  1.2       +10 -20    JBossCache/src/org/jboss/cache/lock/StripedLock.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: StripedLock.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/StripedLock.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- StripedLock.java	19 Jun 2007 10:45:43 -0000	1.1
  +++ StripedLock.java	19 Jun 2007 13:05:18 -0000	1.2
  @@ -1,8 +1,6 @@
   package org.jboss.cache.lock;
   
   import net.jcip.annotations.ThreadSafe;
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.Fqn;
   
   import java.util.concurrent.locks.ReentrantReadWriteLock;
  @@ -28,9 +26,7 @@
      private int lockSegmentMask;
      private int lockSegmentShift;
   
  -   private ReentrantReadWriteLock[] sharedLocks;
  -   private Log log = LogFactory.getLog(StripedLock.class);
  -
  +   ReentrantReadWriteLock[] sharedLocks;
   
      /**
       * This constructor just calls {@link #StripedLock(int)} with a default concurrency value of 20.
  @@ -71,7 +67,6 @@
      public void acquireLock(Fqn fqn, boolean writeLock)
      {
         ReentrantReadWriteLock lock = getLock(fqn);
  -//      log.error("I want a " + (writeLock ? "WL" : "RL") + " and lock ownership is " + lock.toString());
   
         if (writeLock)
            lock.writeLock().lock();
  @@ -87,38 +82,33 @@
      public void releaseLock(Fqn fqn)
      {
         ReentrantReadWriteLock lock = getLock(fqn);
  -//      log.error("I want to release the lock.  Status " + lock);
  -      try
  -      {
  -         lock.readLock().unlock();
  -      }
  -      catch (IllegalMonitorStateException imsa)
  -      {
  -         log.trace("Caught exception attempting to release a read lock.  Perhaps we have a write lock?");
  +      if (lock.isWriteLockedByCurrentThread())
            lock.writeLock().unlock();
  -      }
  +      else
  +         lock.readLock().unlock();
      }
   
  -   protected ReentrantReadWriteLock getLock(Object o)
  +   ReentrantReadWriteLock getLock(Object o)
      {
         return sharedLocks[hashToIndex(o)];
      }
   
  -   protected int hashToIndex(Object o)
  +   int hashToIndex(Object o)
      {
         return (hash(o) >>> lockSegmentShift) & lockSegmentMask;
      }
   
      /**
       * Returns a hash code for non-null Object x.
  -    * Uses the same hash code spreader as most other java.util hash tables.
  +    * Uses the same hash code spreader as most other java.util hash tables, except that this uses the string representation
  +    * of the object passed in.
       *
       * @param x the object serving as a key
       * @return the hash code
       */
  -   private int hash(Object x)
  +   int hash(Object x)
      {
  -      int h = x.hashCode();
  +      int h = x.toString().hashCode();
         h += ~(h << 9);
         h ^= (h >>> 14);
         h += (h << 4);
  
  
  



More information about the jboss-cvs-commits mailing list