[Summary] Added possibility to identify IO thread which does not have required resour...
authorGZharun <grygoriiz@wavesglobal.com>
Tue, 24 Feb 2015 12:27:36 +0000 (14:27 +0200)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 29 Jun 2015 18:16:42 +0000 (14:16 -0400)
Conflicts:
libs/ardour/ardour/audioengine.h
libs/backends/wavesaudio/waves_audiobackend.cc
libs/pbd/pbd/pool.h

libs/ardour/ardour/audioengine.h
libs/ardour/ardour/session_event.h
libs/ardour/audioengine.cc
libs/ardour/session_events.cc
libs/backends/wavesaudio/waves_audiobackend.cc
libs/pbd/pbd/pool.h
libs/pbd/pool.cc

index 330de4e285a29017a8de8f718462b263f8cc0acc..d1e3f8a7ef96002e65458f448d710240f2a38782 100644 (file)
@@ -209,6 +209,9 @@ class LIBARDOUR_API AudioEngine : public SessionHandlePtr, public PortManager
        void latency_callback (bool for_playback);
        void halted_callback (const char* reason);
 
+       /* checks if current thread is properly set up for audio processing */
+       static bool thread_initialised_for_audio_processing ();
+
        /* sets up the process callback thread */
        static void thread_init_callback (void *);
 
index 96145e7b295aee94ba80b73e7e72d9a56aa2daf3..0b29596408efa7e30ef1b1cd4b039022ebdca30b 100644 (file)
@@ -134,6 +134,7 @@ public:
 
        static const framepos_t Immediate = -1;
 
+    static bool has_per_thread_pool ();
        static void create_per_thread_pool (const std::string& n, uint32_t nitems);
        static void init_event_pool ();
 
index c18b5dde384089f7cae68bb0e6d464a87006089f..86fc5f0221c3d6e7f489d12bf3f6afc39f5f5159 100644 (file)
@@ -1151,6 +1151,12 @@ AudioEngine::set_systemic_output_latency (uint32_t ol)
        return _backend->set_systemic_output_latency  (ol);
 }
 
+bool
+AudioEngine::thread_initialised_for_audio_processing ()
+{
+    return SessionEvent::has_per_thread_pool () && AsyncMIDIPort::is_process_thread();
+}
+
 /* END OF BACKEND PROXY API */
 
 void
index 53a26363b06cf57dfd8d43bd2f81595763638c1e..f37578114332c0865c7ae8e84e677e884b1d3b13 100644 (file)
@@ -42,6 +42,12 @@ SessionEvent::init_event_pool ()
        pool = new PerThreadPool;
 }
 
+bool
+SessionEvent::has_per_thread_pool ()
+{
+    return pool->has_per_thread_pool ();
+}
+
 void
 SessionEvent::create_per_thread_pool (const std::string& name, uint32_t nitems)
 {
index 8a1661b580195235d4a955dee3d93da8007e6361..fa3a7c8c95b0da5296f1a717c8636bd175de02da 100644 (file)
@@ -758,6 +758,17 @@ WavesAudioBackend::_audio_device_callback (const float* input_buffer,
         AudioEngine::thread_init_callback (this);
     }
 
+    if ( !engine.thread_initialised_for_audio_processing () ) {
+           std::cerr << "\tWavesAudioBackend::_audio_device_callback (): It's an attempt to call process callback from the thread which didn't initialize it " << std::endl;
+           
+           if (process_id != pthread_self() ) {
+                   std::cerr << "Process thread ID has changed. Expected thread: " << process_id << " current thread: " << pthread_self() << std::dec << " !" << std::endl;
+                   process_id = pthread_self();
+           }
+           
+           AudioEngine::thread_init_callback (this);
+    }
+
     engine.process_callback (nframes);
     
     _write_audio_data_to_device (output_buffer, nframes);
index cfd782a794fa50a029f7cda0968f8b5f48a5d3af..aff3f7ea21f5ec9e708a7cf27200145b3c859b7f 100644 (file)
@@ -129,7 +129,7 @@ class LIBPBD_API PerThreadPool
 
        void  create_per_thread_pool (std::string name, unsigned long item_size, unsigned long nitems);
        CrossThreadPool* per_thread_pool (bool must_exist = true);
-
+       bool has_per_thread_pool ();
        void set_trash (RingBuffer<CrossThreadPool*>* t);
        void add_to_trash (CrossThreadPool *);
 
index 020f296f61bf7e3ea13b63515c792539eb5dc01e..404fab60e366ed9b679fd489d3a9028043000b20 100644 (file)
@@ -175,6 +175,20 @@ PerThreadPool::create_per_thread_pool (string n, unsigned long isize, unsigned l
        _key.set (new CrossThreadPool (n, isize, nitems, this));
 }
 
+/** @return True if CrossThreadPool for the current thread exists,
+ *  False otherwise
+ */
+bool
+PerThreadPool::has_per_thread_pool ()
+{
+    CrossThreadPool* p = _key.get();
+    if (p) {
+        return true;
+    }
+    return false;
+}
+
+
 /** @return CrossThreadPool for the current thread, which must previously have been created by
  *  calling create_per_thread_pool in the current thread.
  */