From fa2dcea820fb3aa9ba244a7e28890c4c9296019a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 11 Jul 2013 15:08:10 -0400 Subject: Use jack_native_thread_t for portability Requires future attention in AudioEngine due to timbyr's use JACK2 extension to JACK API --- libs/ardour/ardour/audioengine.h | 3 ++- libs/ardour/ardour/graph.h | 2 +- libs/ardour/audioengine.cc | 24 +++++++++++++++++++++++- libs/ardour/graph.cc | 7 +++---- 4 files changed, 29 insertions(+), 7 deletions(-) (limited to 'libs/ardour') diff --git a/libs/ardour/ardour/audioengine.h b/libs/ardour/ardour/audioengine.h index 165ad6744f..363238baad 100644 --- a/libs/ardour/ardour/audioengine.h +++ b/libs/ardour/ardour/audioengine.h @@ -258,7 +258,8 @@ _ the regular process() call to session->process() is not made. static void destroy(); void died (); - int create_process_thread (boost::function, pthread_t*, size_t stacksize); + int create_process_thread (boost::function, jack_native_thread_t*, size_t stacksize); + bool stop_process_thread (jack_native_thread_t); private: static AudioEngine* _instance; diff --git a/libs/ardour/ardour/graph.h b/libs/ardour/ardour/graph.h index cac09d34af..0a288d68d3 100644 --- a/libs/ardour/ardour/graph.h +++ b/libs/ardour/ardour/graph.h @@ -92,7 +92,7 @@ protected: virtual void session_going_away (); private: - std::list _thread_list; + std::list _thread_list; volatile bool _quit_threads; void reset_thread_list (); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 08de54960c..690012e529 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -1548,7 +1548,7 @@ AudioEngine::is_realtime () const } int -AudioEngine::create_process_thread (boost::function f, pthread_t* thread, size_t stacksize) +AudioEngine::create_process_thread (boost::function f, jack_native_thread_t* thread, size_t stacksize) { GET_PRIVATE_JACK_POINTER_RET (_jack, 0); ThreadData* td = new ThreadData (this, f, stacksize); @@ -1561,6 +1561,28 @@ AudioEngine::create_process_thread (boost::function f, pthread_t* thread return 0; } +bool +AudioEngine::stop_process_thread (jack_native_thread_t thread) +{ + /** + * can't use GET_PRIVATE_JACK_POINTER_RET (_jack, 0) here + * because _jack is 0 when this is called. At least for + * Jack 2 _jack arg is not used so it should be OK + */ + +#ifdef USING_JACK2_EXPANSION_OF_JACK_API + if (jack_client_stop_thread (_jack, thread) != 0) { + error << "AudioEngine: cannot stop process thread" << endmsg; + return false; + } +#else + void* status; + pthread_join (thread, &status); +#endif + + return true; +} + void* AudioEngine::_start_process_thread (void* arg) { diff --git a/libs/ardour/graph.cc b/libs/ardour/graph.cc index cb0fa1b21a..3eb601e82b 100644 --- a/libs/ardour/graph.cc +++ b/libs/ardour/graph.cc @@ -101,7 +101,7 @@ Graph::reset_thread_list () } Glib::Threads::Mutex::Lock lm (_session.engine().process_lock()); - pthread_t a_thread; + jack_native_thread_t a_thread; if (!_thread_list.empty()) { drop_threads (); @@ -146,9 +146,8 @@ Graph::drop_threads () _callback_start_sem.signal (); - for (list::iterator i = _thread_list.begin(); i != _thread_list.end(); ++i) { - void* status; - pthread_join (*i, &status); + for (list::iterator i = _thread_list.begin(); i != _thread_list.end(); ++i) { + AudioEngine::instance()->stop_process_thread(*i); } _thread_list.clear (); -- cgit v1.2.3