Use jack_native_thread_t for portability
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 11 Jul 2013 19:08:10 +0000 (15:08 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 11 Jul 2013 19:08:10 +0000 (15:08 -0400)
Requires future attention in AudioEngine due to timbyr's use JACK2 extension to JACK API

libs/ardour/ardour/audioengine.h
libs/ardour/ardour/graph.h
libs/ardour/audioengine.cc
libs/ardour/graph.cc

index 165ad6744f341db3d809bc56b22ee6f0744a748c..363238baadcee52e88029274a5c2e4ed1a9e7847 100644 (file)
@@ -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<void()>, pthread_t*, size_t stacksize);
+       int create_process_thread (boost::function<void()>, jack_native_thread_t*, size_t stacksize);
+       bool stop_process_thread (jack_native_thread_t);
 
 private:
        static AudioEngine*       _instance;
index cac09d34af386ee8a3ec8ac5c606646e31720c3a..0a288d68d39db60c4a62c6f61d2113d0f450e73a 100644 (file)
@@ -92,7 +92,7 @@ protected:
        virtual void session_going_away ();
 
 private:
-       std::list<pthread_t> _thread_list;
+       std::list<jack_native_thread_t> _thread_list;
        volatile bool        _quit_threads;
 
        void reset_thread_list ();
index 08de54960c0ae1a6972f3d0aaccade1850e1ff9c..690012e52946e36b4400cf147696ad1f25ed6296 100644 (file)
@@ -1548,7 +1548,7 @@ AudioEngine::is_realtime () const
 }
 
 int
-AudioEngine::create_process_thread (boost::function<void()> f, pthread_t* thread, size_t stacksize)
+AudioEngine::create_process_thread (boost::function<void()> 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<void()> 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)
 {
index cb0fa1b21ae28b8d45ea3aaab7af32f522f525d0..3eb601e82b3e0bb4d3c14656914c7b7fee04ccd8 100644 (file)
@@ -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<pthread_t>::iterator i = _thread_list.begin(); i != _thread_list.end(); ++i) {
-                void* status;
-                pthread_join (*i, &status);
+        for (list<jack_native_thread_t>::iterator i = _thread_list.begin(); i != _thread_list.end(); ++i) {
+                AudioEngine::instance()->stop_process_thread(*i);
         }
 
         _thread_list.clear ();