summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGZharun <grygoriiz@wavesglobal.com>2015-02-24 14:27:36 +0200
committerPaul Davis <paul@linuxaudiosystems.com>2015-06-29 14:16:42 -0400
commitef59fbffa17c6ed08e22d17daaea0d6fa4c4ce18 (patch)
tree08d0852c0795b0d769686a713e006db8dba7f93f
parent017e580c9f1f03f6dab574406aaad028bebc452a (diff)
[Summary] Added possibility to identify IO thread which does not have required resources initialized during process callback handling
Conflicts: libs/ardour/ardour/audioengine.h libs/backends/wavesaudio/waves_audiobackend.cc libs/pbd/pbd/pool.h
-rw-r--r--libs/ardour/ardour/audioengine.h3
-rw-r--r--libs/ardour/ardour/session_event.h1
-rw-r--r--libs/ardour/audioengine.cc6
-rw-r--r--libs/ardour/session_events.cc6
-rw-r--r--libs/backends/wavesaudio/waves_audiobackend.cc11
-rw-r--r--libs/pbd/pbd/pool.h2
-rw-r--r--libs/pbd/pool.cc14
7 files changed, 42 insertions, 1 deletions
diff --git a/libs/ardour/ardour/audioengine.h b/libs/ardour/ardour/audioengine.h
index 330de4e285..d1e3f8a7ef 100644
--- a/libs/ardour/ardour/audioengine.h
+++ b/libs/ardour/ardour/audioengine.h
@@ -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 *);
diff --git a/libs/ardour/ardour/session_event.h b/libs/ardour/ardour/session_event.h
index 96145e7b29..0b29596408 100644
--- a/libs/ardour/ardour/session_event.h
+++ b/libs/ardour/ardour/session_event.h
@@ -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 ();
diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc
index c18b5dde38..86fc5f0221 100644
--- a/libs/ardour/audioengine.cc
+++ b/libs/ardour/audioengine.cc
@@ -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
diff --git a/libs/ardour/session_events.cc b/libs/ardour/session_events.cc
index 53a26363b0..f375781143 100644
--- a/libs/ardour/session_events.cc
+++ b/libs/ardour/session_events.cc
@@ -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)
{
diff --git a/libs/backends/wavesaudio/waves_audiobackend.cc b/libs/backends/wavesaudio/waves_audiobackend.cc
index 8a1661b580..fa3a7c8c95 100644
--- a/libs/backends/wavesaudio/waves_audiobackend.cc
+++ b/libs/backends/wavesaudio/waves_audiobackend.cc
@@ -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);
diff --git a/libs/pbd/pbd/pool.h b/libs/pbd/pbd/pool.h
index cfd782a794..aff3f7ea21 100644
--- a/libs/pbd/pbd/pool.h
+++ b/libs/pbd/pbd/pool.h
@@ -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 *);
diff --git a/libs/pbd/pool.cc b/libs/pbd/pool.cc
index 020f296f61..404fab60e3 100644
--- a/libs/pbd/pool.cc
+++ b/libs/pbd/pool.cc
@@ -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.
*/