changeset 589:09c8195c371d

Avoid exiting with locked mutex
author Chris Cannam
date Mon, 22 Jul 2013 13:24:06 +0100
parents e8881f405b8f
children c06a9e8e2748 58ced0b1e02f
files main/main.cpp
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/main/main.cpp	Fri Jul 19 15:45:40 2013 +0100
+++ b/main/main.cpp	Mon Jul 22 13:24:06 2013 +0100
@@ -172,16 +172,21 @@
 */
 
 static QMutex cleanupMutex;
+static bool cleanedUp = false;
 
 static void
 signalHandler(int /* signal */)
 {
     // Avoid this happening more than once across threads
 
+    std::cerr << "signalHandler: cleaning up and exiting" << std::endl;
     cleanupMutex.lock();
-    std::cerr << "signalHandler: cleaning up and exiting" << std::endl;
-    TempDirectory::getInstance()->cleanup();
-    exit(0); // without releasing mutex
+    if (!cleanedUp) {
+        TempDirectory::getInstance()->cleanup();
+        cleanedUp = true;
+    }
+    cleanupMutex.unlock();
+    exit(0);
 }
 
 class SVApplication : public QApplication
@@ -422,8 +427,12 @@
 
     cleanupMutex.lock();
 
-    TransformFactory::deleteInstance();
-    TempDirectory::getInstance()->cleanup();
+    if (!cleanedUp) {
+        TransformFactory::deleteInstance();
+        TempDirectory::getInstance()->cleanup();
+        cleanedUp = true;
+    }
+
     application.releaseMainWindow();
 
 #ifdef HAVE_FFTW3F
@@ -447,6 +456,8 @@
 
     cleanupMutex.unlock();
 
+    cleanupMutex.unlock();
+
     return rv;
 }