[jboss-cvs] JBoss Messaging SVN: r4078 - branches/trunk_tmp_aio/src/main/org/jboss/messaging/core/asyncio/impl.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 17 16:52:08 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-04-17 16:52:08 -0400 (Thu, 17 Apr 2008)
New Revision: 4078

Modified:
   branches/trunk_tmp_aio/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java
Log:
Better fixes

Modified: branches/trunk_tmp_aio/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java
===================================================================
--- branches/trunk_tmp_aio/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java	2008-04-17 20:44:33 UTC (rev 4077)
+++ branches/trunk_tmp_aio/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java	2008-04-17 20:52:08 UTC (rev 4078)
@@ -8,7 +8,6 @@
 package org.jboss.messaging.core.asyncio.impl;
 
 import java.nio.ByteBuffer;
-import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -36,7 +35,8 @@
     Lock readLock = lock.readLock();
     
     ReadWriteLock lockPoller = new ReentrantReadWriteLock();
-    Lock pollerLock = lockPoller.writeLock();
+    Lock readPollerLock = lockPoller.readLock();
+    Lock writePollerLock = lockPoller.writeLock();
     
     /**
      *  Warning: Beware of the C++ pointer! It will bite you! :-)
@@ -87,24 +87,20 @@
     
     class PollerThread extends Thread
     {
-        CountDownLatch latch;
-        PollerThread (CountDownLatch latch)
+        PollerThread ()
         {
             super("NativePoller for " + fileName);
-            this.latch = latch;
         }
         public void run()
         {
-           pollerLock.lock();
            // informing caller that this thread already has the lock
-           latch.countDown();
            try
            {
             pollEvents();
            }
            finally
            {
-              pollerLock.unlock();
+              readPollerLock.unlock();
            }
         }
     }
@@ -115,7 +111,9 @@
        
        writeLock.lock();
        stopPoller(handler);
-       pollerLock.lock();
+       
+       // We need to make sure we won't call close until Poller is completely done, or we might get beautiful GPFs
+       writePollerLock.lock();
        try
        {
         closeInternal(handler);
@@ -125,7 +123,7 @@
        finally
        {
           writeLock.unlock();
-          pollerLock.unlock();
+          writePollerLock.unlock();
        }
     }
     
@@ -208,14 +206,12 @@
     private synchronized void  startPoller()
     {
         checkOpened();
-        CountDownLatch latch = new CountDownLatch(1);
-        poller = new PollerThread(latch); 
+        readPollerLock.lock();
+
+        poller = new PollerThread(); 
         try
         {
            poller.start();
-           // We should wait the Poller to hold the Lock, or we could have a race condition between closes and open if they are happening too fast
-           // what could cause core dumps or GPFs
-           latch.await();
         }
         catch (Exception ex)
         {




More information about the jboss-cvs-commits mailing list