comparison main/main.cpp @ 589:09c8195c371d

Avoid exiting with locked mutex
author Chris Cannam
date Mon, 22 Jul 2013 13:24:06 +0100
parents 0b094b0fdcc4
children c06a9e8e2748 b8801b96426b
comparison
equal deleted inserted replaced
588:e8881f405b8f 589:09c8195c371d
170 of the window. 170 of the window.
171 171
172 */ 172 */
173 173
174 static QMutex cleanupMutex; 174 static QMutex cleanupMutex;
175 static bool cleanedUp = false;
175 176
176 static void 177 static void
177 signalHandler(int /* signal */) 178 signalHandler(int /* signal */)
178 { 179 {
179 // Avoid this happening more than once across threads 180 // Avoid this happening more than once across threads
180 181
182 std::cerr << "signalHandler: cleaning up and exiting" << std::endl;
181 cleanupMutex.lock(); 183 cleanupMutex.lock();
182 std::cerr << "signalHandler: cleaning up and exiting" << std::endl; 184 if (!cleanedUp) {
183 TempDirectory::getInstance()->cleanup(); 185 TempDirectory::getInstance()->cleanup();
184 exit(0); // without releasing mutex 186 cleanedUp = true;
187 }
188 cleanupMutex.unlock();
189 exit(0);
185 } 190 }
186 191
187 class SVApplication : public QApplication 192 class SVApplication : public QApplication
188 { 193 {
189 public: 194 public:
420 425
421 gui->hide(); 426 gui->hide();
422 427
423 cleanupMutex.lock(); 428 cleanupMutex.lock();
424 429
425 TransformFactory::deleteInstance(); 430 if (!cleanedUp) {
426 TempDirectory::getInstance()->cleanup(); 431 TransformFactory::deleteInstance();
432 TempDirectory::getInstance()->cleanup();
433 cleanedUp = true;
434 }
435
427 application.releaseMainWindow(); 436 application.releaseMainWindow();
428 437
429 #ifdef HAVE_FFTW3F 438 #ifdef HAVE_FFTW3F
430 settings.beginGroup("FFTWisdom"); 439 settings.beginGroup("FFTWisdom");
431 char *cwisdom = fftwf_export_wisdom_to_string(); 440 char *cwisdom = fftwf_export_wisdom_to_string();
442 #endif 451 #endif
443 settings.endGroup(); 452 settings.endGroup();
444 #endif 453 #endif
445 454
446 delete gui; 455 delete gui;
456
457 cleanupMutex.unlock();
447 458
448 cleanupMutex.unlock(); 459 cleanupMutex.unlock();
449 460
450 return rv; 461 return rv;
451 } 462 }