[jboss-cvs] JBossAS SVN: r69485 - projects/aop/branches/deadlocks/aop/src/main/org/jboss/aop/util.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 30 07:05:40 EST 2008


Author: kabir.khan at jboss.com
Date: 2008-01-30 07:05:40 -0500 (Wed, 30 Jan 2008)
New Revision: 69485

Added:
   projects/aop/branches/deadlocks/aop/src/main/org/jboss/aop/util/LoggingReentrantReadWriteLock.java
Log:


Added: projects/aop/branches/deadlocks/aop/src/main/org/jboss/aop/util/LoggingReentrantReadWriteLock.java
===================================================================
--- projects/aop/branches/deadlocks/aop/src/main/org/jboss/aop/util/LoggingReentrantReadWriteLock.java	                        (rev 0)
+++ projects/aop/branches/deadlocks/aop/src/main/org/jboss/aop/util/LoggingReentrantReadWriteLock.java	2008-01-30 12:05:40 UTC (rev 69485)
@@ -0,0 +1,87 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.aop.util;
+
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class LoggingReentrantReadWriteLock
+{
+   ReentrantReadWriteLock delegate = new ReentrantReadWriteLock();
+   volatile Thread readLockThread;
+   
+   public void lockRead()
+   {
+      lockOrUnlockRead(true);
+   }
+   
+   public void unlockRead()
+   {
+      lockOrUnlockRead(false);
+   }
+   
+   private void lockOrUnlockRead(boolean lock)
+   {
+      if (lock)
+      {
+         delegate.readLock().lock();
+         readLockThread = Thread.currentThread();
+      }
+      else
+      {
+         readLockThread = null;
+         delegate.readLock().unlock();
+      }
+   }
+
+   public void lockWrite()
+   {
+      lockOrUnlockWrite(true);
+   }
+   
+   public void unlockWrite()
+   {
+      lockOrUnlockWrite(false);
+   }
+   
+   private void lockOrUnlockWrite(boolean lock)
+   {
+      if (lock)
+      {
+         Thread t = readLockThread;
+         if (t != null && t == Thread.currentThread())
+         {
+            throw new RuntimeException(Thread.currentThread() + " is already read locked!!!");
+         }
+         delegate.writeLock().lock();
+      }
+      else
+      {
+         delegate.writeLock().unlock();
+      }
+   }
+
+}




More information about the jboss-cvs-commits mailing list