From c9055547f3df7bdfa3e37b5d0f6c388cbb4d8005 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 19 Nov 2020 22:16:42 -0700 Subject: [PATCH] set thread-local variable infrastructure for process thread & process graph --- libs/ardour/ardour/graph.h | 2 ++ libs/ardour/ardour/session.h | 2 ++ libs/ardour/graph.cc | 10 ++++++++++ libs/ardour/session_process.cc | 10 ++++++++++ 4 files changed, 24 insertions(+) diff --git a/libs/ardour/ardour/graph.h b/libs/ardour/ardour/graph.h index 85d4ef76bc..901ab779d1 100644 --- a/libs/ardour/ardour/graph.h +++ b/libs/ardour/ardour/graph.h @@ -139,6 +139,8 @@ private: /* engine / thread connection */ PBD::ScopedConnectionList engine_connections; void engine_stopped (); + + void setup_thread_local_variables (); }; } // namespace diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index c747860642..d95319a810 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -2284,6 +2284,8 @@ private: std::string unnamed_file_name () const; GATOMIC_QUAL gint _update_pretty_names; + + void setup_thread_local_variables (); }; diff --git a/libs/ardour/graph.cc b/libs/ardour/graph.cc index c815dd53e6..d1b1e27c9c 100644 --- a/libs/ardour/graph.cc +++ b/libs/ardour/graph.cc @@ -27,6 +27,8 @@ #include "pbd/debug_rt_alloc.h" #include "pbd/pthread_utils.h" +#include "temporal/superclock.h" + #include "ardour/audioengine.h" #include "ardour/debug.h" #include "ardour/graph.h" @@ -467,6 +469,7 @@ Graph::helper_thread () pt->get_buffers (); while (!g_atomic_int_get (&_terminate)) { + setup_thread_local_variables (); run_one (); } @@ -520,6 +523,7 @@ again: /* After setup, the main-thread just becomes a normal worker */ while (!g_atomic_int_get (&_terminate)) { + setup_thread_local_variables (); run_one (); } @@ -527,6 +531,12 @@ again: delete (pt); } +void +Graph::setup_thread_local_variables () +{ + Temporal::_thread_sample_rate = _session.sample_rate (); +} + void Graph::dump (int chain) const { diff --git a/libs/ardour/session_process.cc b/libs/ardour/session_process.cc index 2f51103b28..9485143e55 100644 --- a/libs/ardour/session_process.cc +++ b/libs/ardour/session_process.cc @@ -35,6 +35,8 @@ #include +#include "temporal/superclock.h" + #include "ardour/audioengine.h" #include "ardour/auditioner.h" #include "ardour/butler.h" @@ -67,6 +69,12 @@ using namespace std; #define TFSM_LOCATE(target,ltd,loop,force) { _transport_fsm->enqueue (new TransportFSM::Event (TransportFSM::Locate,target,ltd,loop,force)); } +void +Session::setup_thread_local_variables () +{ + Temporal::_thread_sample_rate = sample_rate(); +} + /** Called by the audio engine when there is work to be done with JACK. * @param nframes Number of samples to process. */ @@ -78,6 +86,8 @@ Session::process (pframes_t nframes) samplepos_t transport_at_start = _transport_sample; + setup_thread_local_variables (); + _silent = false; if (processing_blocked()) {