*/
#include <stdio.h>
#include <cmath>
+#include <xmmintrin.h>
#include "pbd/compose.h"
#include "pbd/debug_rt_alloc.h"
reset_thread_list ();
- Config->ParameterChanged.connect_same_thread (processor_usage_connection, boost::bind (&Graph::parameter_changed, this, _1));
-
#ifdef DEBUG_RT_ALLOC
graph = this;
pbd_alloc_allowed = &::alloc_allowed;
#endif
}
-void
-Graph::parameter_changed (std::string param)
-{
- if (param == X_("processor-usage")) {
- reset_thread_list ();
- }
-}
-
/** Set up threads for running the graph */
void
Graph::reset_thread_list ()
{
uint32_t num_threads = how_many_dsp_threads ();
+ /* For now, we shouldn't be using the graph code if we only have 1 DSP thread */
+ assert (num_threads > 1);
+
/* don't bother doing anything here if we already have the right
number of threads.
*/
drop_threads ();
}
-#if 0
- /* XXX this only makes sense when we can use just the AudioEngine thread
- and still keep the graph current with the route list
- */
- if (num_threads <= 1) {
- /* no point creating 1 thread - the AudioEngine already gives us one
- */
- return;
- }
-#endif
- if (AudioEngine::instance()->create_process_thread (boost::bind (&Graph::main_thread, this), &a_thread, 100000) == 0) {
- _thread_list.push_back (a_thread);
+ if (AudioEngine::instance()->create_process_thread (boost::bind (&Graph::main_thread, this), &a_thread, 100000) != 0) {
+ throw failed_constructor ();
}
+ _thread_list.push_back (a_thread);
+
for (uint32_t i = 1; i < num_threads; ++i) {
- if (AudioEngine::instance()->create_process_thread (boost::bind (&Graph::helper_thread, this), &a_thread, 100000) == 0) {
- _thread_list.push_back (a_thread);
+ if (AudioEngine::instance()->create_process_thread (boost::bind (&Graph::helper_thread, this), &a_thread, 100000) != 0) {
+ throw failed_constructor ();
}
+
+ _thread_list.push_back (a_thread);
}
}
_finished_refcount = _init_finished_refcount[chain];
/* Trigger the initial nodes for processing, which are the ones at the `input' end */
+ pthread_mutex_lock (&_trigger_mutex);
for (i=_init_trigger_list[chain].begin(); i!=_init_trigger_list[chain].end(); i++) {
- trigger (i->get ());
+ /* don't use ::trigger here, as we have already locked the mutex */
+ _trigger_queue.push_back (i->get ());
}
+ pthread_mutex_unlock (&_trigger_mutex);
}
void
Graph::trigger (GraphNode* n)
{
- pthread_mutex_lock (&_trigger_mutex);
+ pthread_mutex_lock (&_trigger_mutex);
_trigger_queue.push_back (n);
- pthread_mutex_unlock (&_trigger_mutex);
+ pthread_mutex_unlock (&_trigger_mutex);
}
/** Called when a node at the `output' end of the chain (ie one that has no-one to feed)
return false;
}
-static void get_rt()
-{
- if (!jack_is_realtime (AudioEngine::instance()->jack())) {
- return;
- }
-
- int priority = jack_client_real_time_priority (AudioEngine::instance()->jack());
-
- if (priority) {
- struct sched_param rtparam;
-
- memset (&rtparam, 0, sizeof (rtparam));
- rtparam.sched_priority = priority;
-
- pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam);
- }
-}
-
void
Graph::helper_thread()
{
resume_rt_malloc_checks ();
pt->get_buffers();
- get_rt();
while(1) {
if (run_one()) {
resume_rt_malloc_checks ();
pt->get_buffers();
- get_rt();
again:
_callback_start_sem.wait ();
bool
Graph::in_process_thread () const
{
- list<pthread_t>::const_iterator i = _thread_list.begin ();
- while (i != _thread_list.end() && *i != pthread_self ()) {
- ++i;
+ for (list<pthread_t>::const_iterator i = _thread_list.begin (); i != _thread_list.end(); ++i) {
+ if (*i == pthread_self()) {
+ return true;
+ }
}
-
- return i != _thread_list.end ();
+ return false;
}