Terminate Analysis thread at exit
This prevents a crash at exit if the analyzer is still analyzing when Ardour terminates. A possible downside is that an ongoing analysis will keep the application running for a bit longer.
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
|
||||
#include "pbd/compose.h"
|
||||
#include "pbd/error.h"
|
||||
#include "pbd/pthread_utils.h"
|
||||
|
||||
#include "pbd/i18n.h"
|
||||
|
||||
@@ -36,25 +35,37 @@ using namespace std;
|
||||
using namespace ARDOUR;
|
||||
using namespace PBD;
|
||||
|
||||
Analyser* Analyser::the_analyser = 0;
|
||||
Glib::Threads::Mutex Analyser::analysis_active_lock;
|
||||
Glib::Threads::Mutex Analyser::analysis_queue_lock;
|
||||
Glib::Threads::Cond Analyser::SourcesToAnalyse;
|
||||
list<boost::weak_ptr<Source> > Analyser::analysis_queue;
|
||||
bool Analyser::analysis_thread_run = false;
|
||||
PBD::Thread* Analyser::analysis_thread = 0;
|
||||
|
||||
Analyser::Analyser ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Analyser::~Analyser ()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Analyser::init ()
|
||||
{
|
||||
PBD::Thread::create (sigc::ptr_fun (&Analyser::work), "Analyzer");
|
||||
if (analysis_thread_run) {
|
||||
return;
|
||||
}
|
||||
analysis_thread_run = true;
|
||||
analysis_thread = PBD::Thread::create (sigc::ptr_fun (&Analyser::work), "Analyzer");
|
||||
}
|
||||
|
||||
void
|
||||
Analyser::terminate ()
|
||||
{
|
||||
if (!analysis_thread_run) {
|
||||
return;
|
||||
}
|
||||
analysis_thread_run = false;
|
||||
SourcesToAnalyse.broadcast ();
|
||||
analysis_thread->join ();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -82,10 +93,15 @@ Analyser::work ()
|
||||
analysis_queue_lock.lock ();
|
||||
|
||||
wait:
|
||||
if (analysis_queue.empty()) {
|
||||
if (analysis_queue.empty() && analysis_thread_run) {
|
||||
SourcesToAnalyse.wait (analysis_queue_lock);
|
||||
}
|
||||
|
||||
if (!analysis_thread_run) {
|
||||
analysis_queue_lock.unlock ();
|
||||
break;
|
||||
}
|
||||
|
||||
if (analysis_queue.empty()) {
|
||||
goto wait;
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
#ifndef __ardour_analyser_h__
|
||||
#define __ardour_analyser_h__
|
||||
|
||||
#include <glibmm/threads.h>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "pbd/pthread_utils.h"
|
||||
#include "ardour/libardour_visibility.h"
|
||||
|
||||
namespace ARDOUR {
|
||||
@@ -32,22 +32,22 @@ class Source;
|
||||
class TransientDetector;
|
||||
|
||||
class LIBARDOUR_API Analyser {
|
||||
|
||||
public:
|
||||
public:
|
||||
Analyser();
|
||||
~Analyser ();
|
||||
|
||||
static void init ();
|
||||
static void terminate ();
|
||||
static void queue_source_for_analysis (boost::shared_ptr<Source>, bool force);
|
||||
static void work ();
|
||||
static void flush ();
|
||||
|
||||
private:
|
||||
static Analyser* the_analyser;
|
||||
private:
|
||||
static Glib::Threads::Mutex analysis_active_lock;
|
||||
static Glib::Threads::Mutex analysis_queue_lock;
|
||||
static Glib::Threads::Cond SourcesToAnalyse;
|
||||
static std::list<boost::weak_ptr<Source> > analysis_queue;
|
||||
static bool analysis_thread_run;
|
||||
static PBD::Thread* analysis_thread;
|
||||
|
||||
static void analyse_audio_file_source (boost::shared_ptr<AudioFileSource>);
|
||||
};
|
||||
|
||||
@@ -738,6 +738,8 @@ ARDOUR::cleanup ()
|
||||
|
||||
delete TriggerBox::worker;
|
||||
|
||||
Analyser::terminate ();
|
||||
|
||||
release_dma_latency ();
|
||||
config_connection.disconnect ();
|
||||
engine_startup_connection.disconnect ();
|
||||
|
||||
Reference in New Issue
Block a user