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

Galder Zamarreno galder.zamarreno at jboss.com
Fri Jun 29 09:33:36 EDT 2007


  User: gzamarreno
  Date: 07/06/29 09:33:36

  Modified:    src/org/jboss/cache/lock   Tag: Branch_JBossCache_1_4_0
                        SimpleReadWriteLock.java StripedLock.java
  Log:
  [JBCACHE-1103] Finished the backport from head.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.1.1.24.1 +29 -30    JBossCache/src/org/jboss/cache/lock/SimpleReadWriteLock.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SimpleReadWriteLock.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/SimpleReadWriteLock.java,v
  retrieving revision 1.1.1.1
  retrieving revision 1.1.1.1.24.1
  diff -u -b -r1.1.1.1 -r1.1.1.1.24.1
  --- SimpleReadWriteLock.java	31 Mar 2005 10:15:06 -0000	1.1.1.1
  +++ SimpleReadWriteLock.java	29 Jun 2007 13:33:36 -0000	1.1.1.1.24.1
  @@ -4,7 +4,7 @@
   
   /**
    * @author Bela Ban
  - * @version $Id: SimpleReadWriteLock.java,v 1.1.1.1 2005/03/31 10:15:06 belaban Exp $
  + * @version $Id: SimpleReadWriteLock.java,v 1.1.1.1.24.1 2007/06/29 13:33:36 gzamarreno Exp $
    */
   public class SimpleReadWriteLock extends ReentrantWriterPreferenceReadWriteLock {
   
  @@ -26,5 +26,4 @@
      }
   
   
  -
   }
  
  
  
  1.5.2.5   +52 -12    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.5.2.4
  retrieving revision 1.5.2.5
  diff -u -b -r1.5.2.4 -r1.5.2.5
  --- StripedLock.java	24 Jun 2007 20:53:56 -0000	1.5.2.4
  +++ StripedLock.java	29 Jun 2007 13:33:36 -0000	1.5.2.5
  @@ -1,13 +1,34 @@
  +/*
  + * JBoss, Home of Professional Open Source.
  + * Copyright 2007, Red Hat Middleware LLC, and individual contributors
  + * as indicated by the @author tags. See the copyright.txt file in the
  + * distribution for a full listing of individual contributors.
  + *
  + * This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  + */
   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.Iterator;
   import java.util.List;
  -import java.util.concurrent.locks.ReentrantReadWriteLock;
  +
  +import EDU.oswego.cs.dl.util.concurrent.ReentrantWriterPreferenceReadWriteLock;
   
   /**
    * A simple implementation of lock striping, using Fqns as the keys to lock on, primarily used to help make
  @@ -21,9 +42,8 @@
    * <p/>
    *
    * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
  - * @since 2.0.0
  + * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
    */
  -//@ThreadSafe
   public class StripedLock
   {
      private static final int DEFAULT_CONCURRENCY = 20;
  @@ -73,26 +93,36 @@
      {
         ReentrantReadWriteLock lock = getLock(fqn);
   
  +      try
  +      {
         if (exclusive)
         {
            // allow for reentrancy
  -         lock.writeLock().lock();
  +            lock.writeLock().acquire();
         }
         else
  -         lock.readLock().lock();
  +         {
  +            lock.readLock().acquire();
  +         }
  +      }
  +      catch (InterruptedException ex)
  +      {
  +         Thread.currentThread().interrupt(); // propagate without throwing, restoring the interrupted status
  +      }
      }
   
      /**
  -    * Releases a lock the caller may be holding. This method is idempotent.
  +    * Releases a lock the caller may be holding.
       *
       * @param fqn the Fqn to release
  +    * @param exclusive if true, a write (exclusive) lock is released, otherwise a read (shared) lock is released.
       */
      public void releaseLock(Fqn fqn)
      {
         ReentrantReadWriteLock lock = getLock(fqn);
         if (lock.isWriteLockedByCurrentThread())
         {
  -         lock.writeLock().unlock();
  +         lock.writeLock().release();
            // check that we still don't have a stale WL
            if (lock.isWriteLockedByCurrentThread() && log.isWarnEnabled())
               log.warn("Write lock still exists on Fqn " + fqn + " for current thread.  Perhaps this was write-locked more than once?");
  @@ -101,7 +131,7 @@
         {
            try
            {
  -            lock.readLock().unlock();
  +            lock.readLock().release();
            }
            catch (IllegalMonitorStateException imse)
            {
  @@ -170,4 +200,14 @@
            acquireLock((Fqn) fqnsIterator.next(), exclusive);
         }
      }
  +
  +   /**
  +    * A lock class that allows querying whether a WL is held by the current thread.
  +    */
  +   class ReentrantReadWriteLock extends ReentrantWriterPreferenceReadWriteLock
  +   {
  +      public boolean isWriteLockedByCurrentThread() {
  +         return activeWriter_ == Thread.currentThread();
  +      }
  +   }
   }
  
  
  



More information about the jboss-cvs-commits mailing list