[jboss-cvs] JBoss Messaging SVN: r4076 - in branches/trunk_tmp_aio: src/main/org/jboss/messaging/core/asyncio/impl and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 17 13:52:54 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-04-17 13:52:54 -0400 (Thu, 17 Apr 2008)
New Revision: 4076

Modified:
   branches/trunk_tmp_aio/native/src/
   branches/trunk_tmp_aio/native/src/AsyncFile.cpp
   branches/trunk_tmp_aio/native/src/LibAIOController.cpp
   branches/trunk_tmp_aio/native/src/org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl.h
   branches/trunk_tmp_aio/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java
   branches/trunk_tmp_aio/tests/src/org/jboss/messaging/core/asyncio/impl/test/integration/SingleThreadWriteNativeTest.java
   branches/trunk_tmp_aio/tests/src/org/jboss/messaging/core/journal/impl/test/unit/JournalImplTestUnit.java
Log:
Fixing core dump caused by race condition on close


Property changes on: branches/trunk_tmp_aio/native/src
___________________________________________________________________
Name: svn:ignore
   - Makefile
Makefile.in
.deps

   + Makefile
Makefile.in
.deps
.libs


Modified: branches/trunk_tmp_aio/native/src/AsyncFile.cpp
===================================================================
--- branches/trunk_tmp_aio/native/src/AsyncFile.cpp	2008-04-17 15:35:25 UTC (rev 4075)
+++ branches/trunk_tmp_aio/native/src/AsyncFile.cpp	2008-04-17 17:52:54 UTC (rev 4076)
@@ -81,14 +81,16 @@
 #endif
 
 	events = (struct io_event *)malloc (maxIO * sizeof (struct io_event));
+	
+	if (events == 0)
+	{
+		throw AIOException (1, "Can't allocate ioEvents");
+	}
 
 }
 
 AsyncFile::~AsyncFile()
 {
-	::pthread_mutex_destroy(&fileMutex);
-	::pthread_mutex_destroy(&pollerMutex);
-	free(events);
 	if (io_queue_release(aioContext))
 	{
 		throw AIOException(2,"Can't release aio");
@@ -97,6 +99,9 @@
 	{
 		throw AIOException(2,"Can't close file");
 	}
+	free(events);
+	::pthread_mutex_destroy(&fileMutex);
+	::pthread_mutex_destroy(&pollerMutex);
 }
 
 int isException (THREAD_CONTEXT threadContext)

Modified: branches/trunk_tmp_aio/native/src/LibAIOController.cpp
===================================================================
--- branches/trunk_tmp_aio/native/src/LibAIOController.cpp	2008-04-17 15:35:25 UTC (rev 4075)
+++ branches/trunk_tmp_aio/native/src/LibAIOController.cpp	2008-04-17 17:52:54 UTC (rev 4076)
@@ -177,6 +177,19 @@
 }
 
 
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_stopPoller
+  (JNIEnv *env, jclass, jlong controllerAddress)
+{
+	try
+	{
+		AIOController * controller = (AIOController *) controllerAddress;
+		controller->fileOutput.stopPoller(env);
+	}
+	catch (AIOException& e)
+	{
+		throwException(env, "java/lang/RuntimeException", e.what());
+	}
+}
 
 JNIEXPORT void JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_closeInternal
   (JNIEnv *env, jclass, jlong controllerAddress)
@@ -184,7 +197,6 @@
 	try
 	{
 		AIOController * controller = (AIOController *) controllerAddress;
-		controller->fileOutput.stopPoller(env);
 		controller->destroy(env);
 		delete controller;
 	}

Modified: branches/trunk_tmp_aio/native/src/org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl.h
===================================================================
--- branches/trunk_tmp_aio/native/src/org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl.h	2008-04-17 15:35:25 UTC (rev 4075)
+++ branches/trunk_tmp_aio/native/src/org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl.h	2008-04-17 17:52:54 UTC (rev 4076)
@@ -51,6 +51,14 @@
 
 /*
  * Class:     org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl
+ * Method:    stopPoller
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_stopPoller
+  (JNIEnv *, jclass, jlong);
+
+/*
+ * Class:     org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl
  * Method:    internalPollEvents
  * Signature: (J)V
  */

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 15:35:25 UTC (rev 4075)
+++ branches/trunk_tmp_aio/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java	2008-04-17 17:52:54 UTC (rev 4076)
@@ -61,20 +61,17 @@
     
 
     
-    public void open(String fileName, int maxIO)
+    public synchronized void open(String fileName, int maxIO)
     {
-       writeLock.lock();
-       try
+       readLock.lock(); // to be released when the poller goes down
+       if (opened)
        {
-          opened = true;
-          this.fileName=fileName;
-          handler = init (fileName, maxIO, log);
-          startPoller();
+          throw new IllegalStateException("AsynchronousFile is already opened");
        }
-       finally
-       {
-          writeLock.unlock();
-       }
+       opened = true;
+       this.fileName=fileName;
+       handler = init (fileName, maxIO, log);
+       startPoller();
     }
     
     class PollerThread extends Thread
@@ -85,16 +82,25 @@
         }
         public void run()
         {
+           try
+           {
             pollEvents();
+           }
+           finally
+           {
+              readLock.unlock();
+           }
         }
     }
     
     public synchronized void close()
     {
+       checkOpened();
+       stopPoller(handler);
+       
        writeLock.lock();
        try
        {
-        checkOpened();
         closeInternal(handler);
         opened = false;
         handler = 0;
@@ -218,6 +224,8 @@
     private static native void fill(long handle, long position, int blocks, long size, byte fillChar);
 
     private static native void closeInternal(long handler);
+
+    private static native void stopPoller(long handler);
     
     /** Poll asynchrounous events from internal queues */
     private static native void internalPollEvents(long handler);

Modified: branches/trunk_tmp_aio/tests/src/org/jboss/messaging/core/asyncio/impl/test/integration/SingleThreadWriteNativeTest.java
===================================================================
--- branches/trunk_tmp_aio/tests/src/org/jboss/messaging/core/asyncio/impl/test/integration/SingleThreadWriteNativeTest.java	2008-04-17 15:35:25 UTC (rev 4075)
+++ branches/trunk_tmp_aio/tests/src/org/jboss/messaging/core/asyncio/impl/test/integration/SingleThreadWriteNativeTest.java	2008-04-17 17:52:54 UTC (rev 4076)
@@ -147,6 +147,17 @@
        
    }
    
+   public void testAnnoyingPoller() throws Exception
+   {
+      final AsynchronousFileImpl controller = new AsynchronousFileImpl();
+      for (int i=0; i< 1000; i++)
+      {
+         controller.open(FILE_NAME, 10000);
+         controller.close();
+         
+      }
+   }
+   
 
    public void testAddBeyongSimultaneousLimit() throws Exception
    {

Modified: branches/trunk_tmp_aio/tests/src/org/jboss/messaging/core/journal/impl/test/unit/JournalImplTestUnit.java
===================================================================
--- branches/trunk_tmp_aio/tests/src/org/jboss/messaging/core/journal/impl/test/unit/JournalImplTestUnit.java	2008-04-17 15:35:25 UTC (rev 4075)
+++ branches/trunk_tmp_aio/tests/src/org/jboss/messaging/core/journal/impl/test/unit/JournalImplTestUnit.java	2008-04-17 17:52:54 UTC (rev 4076)
@@ -1809,6 +1809,7 @@
 		
 	public void testMultipleAddUpdateDeleteDifferentRecordLengths() throws Exception
 	{
+	   log.info("******************************************* here");
 		setup(10, 2048, true);
 		createJournal();
 		startJournal();
@@ -1844,6 +1845,7 @@
 		startJournal();
 		loadAndCheck();
 		stopJournal();			
+      log.info("------------------------------------------- here");
 	}
 	
 	




More information about the jboss-cvs-commits mailing list