Terminate Peak file threads at exit
This commit is contained in:
parent
183f00bbed
commit
75ec5ee87d
|
@ -24,6 +24,7 @@
|
|||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include "pbd/pthread_utils.h"
|
||||
#include "ardour/source.h"
|
||||
|
||||
class XMLNode;
|
||||
|
@ -38,6 +39,7 @@ class LIBARDOUR_API SourceFactory
|
|||
{
|
||||
public:
|
||||
static void init ();
|
||||
static void terminate ();
|
||||
|
||||
static PBD::Signal1<void, boost::shared_ptr<Source>> SourceCreated;
|
||||
|
||||
|
@ -51,6 +53,9 @@ public:
|
|||
static Glib::Threads::Cond PeaksToBuild;
|
||||
static Glib::Threads::Mutex peak_building_lock;
|
||||
|
||||
static bool peak_thread_run;
|
||||
static std::vector<PBD::Thread*> peak_thread_pool;
|
||||
|
||||
static std::list<boost::weak_ptr<AudioSource>> files_with_peaks;
|
||||
|
||||
static int peak_work_queue_length ();
|
||||
|
|
|
@ -739,6 +739,7 @@ ARDOUR::cleanup ()
|
|||
delete TriggerBox::worker;
|
||||
|
||||
Analyser::terminate ();
|
||||
SourceFactory::terminate ();
|
||||
|
||||
release_dma_latency ();
|
||||
config_connection.disconnect ();
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include "pbd/convert.h"
|
||||
#include "pbd/error.h"
|
||||
#include "pbd/pthread_utils.h"
|
||||
|
||||
#include "ardour/audio_playlist_source.h"
|
||||
#include "ardour/audioplaylist.h"
|
||||
|
@ -55,6 +54,8 @@ PBD::Signal1<void, boost::shared_ptr<Source>> SourceFactory::SourceCreated;
|
|||
Glib::Threads::Cond SourceFactory::PeaksToBuild;
|
||||
Glib::Threads::Mutex SourceFactory::peak_building_lock;
|
||||
std::list<boost::weak_ptr<AudioSource>> SourceFactory::files_with_peaks;
|
||||
std::vector<PBD::Thread*> SourceFactory::peak_thread_pool;
|
||||
bool SourceFactory::peak_thread_run = false;
|
||||
|
||||
static int active_threads = 0;
|
||||
|
||||
|
@ -68,17 +69,24 @@ peak_thread_work ()
|
|||
SourceFactory::peak_building_lock.lock ();
|
||||
|
||||
wait:
|
||||
if (SourceFactory::files_with_peaks.empty ()) {
|
||||
if (SourceFactory::files_with_peaks.empty () && SourceFactory::peak_thread_run) {
|
||||
SourceFactory::PeaksToBuild.wait (SourceFactory::peak_building_lock);
|
||||
}
|
||||
|
||||
if (!SourceFactory::peak_thread_run) {
|
||||
SourceFactory::peak_building_lock.unlock ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (SourceFactory::files_with_peaks.empty ()) {
|
||||
goto wait;
|
||||
}
|
||||
|
||||
boost::shared_ptr<AudioSource> as (SourceFactory::files_with_peaks.front ().lock ());
|
||||
SourceFactory::files_with_peaks.pop_front ();
|
||||
++active_threads;
|
||||
if (as) {
|
||||
++active_threads;
|
||||
}
|
||||
SourceFactory::peak_building_lock.unlock ();
|
||||
|
||||
if (!as) {
|
||||
|
@ -103,8 +111,25 @@ SourceFactory::peak_work_queue_length ()
|
|||
void
|
||||
SourceFactory::init ()
|
||||
{
|
||||
if (peak_thread_run) {
|
||||
return;
|
||||
}
|
||||
peak_thread_run = true;
|
||||
for (int n = 0; n < 2; ++n) {
|
||||
PBD::Thread::create (&peak_thread_work);
|
||||
peak_thread_pool.push_back (PBD::Thread::create (&peak_thread_work));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SourceFactory::terminate ()
|
||||
{
|
||||
if (!peak_thread_run) {
|
||||
return;
|
||||
}
|
||||
peak_thread_run = false;
|
||||
PeaksToBuild.broadcast ();
|
||||
for (auto& t : peak_thread_pool) {
|
||||
t->join ();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue