Use PBD namespace for free CPU functions

Ideally never put methods in the global namespace
to prevent potential conflicts.
This commit is contained in:
Robin Gareus 2025-08-15 22:10:31 +02:00
parent b1d5f065db
commit 5ffc3aa28b
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
8 changed files with 14 additions and 10 deletions

View file

@ -157,7 +157,7 @@ namespace ARDOUR {
ExportGraphBuilder::ExportGraphBuilder (Session const & session) ExportGraphBuilder::ExportGraphBuilder (Session const & session)
: session (session) : session (session)
, thread_pool (hardware_concurrency()) , thread_pool (PBD::hardware_concurrency())
{ {
process_buffer_samples = session.engine().samples_per_cycle(); process_buffer_samples = session.engine().samples_per_cycle();
} }

View file

@ -749,7 +749,7 @@ ARDOUR::init (bool try_optimization, const char* localedir, bool with_gui)
* WaveViewThreads::start_threads adds `min (8, hw - 1)` * WaveViewThreads::start_threads adds `min (8, hw - 1)`
* *
*/ */
BufferManager::init (hardware_concurrency () * 3 + 6); BufferManager::init (PBD::hardware_concurrency () * 3 + 6);
PannerManager::instance ().discover_panners (); PannerManager::instance ().discover_panners ();

View file

@ -45,7 +45,7 @@ IOTaskList::IOTaskList (uint32_t n_threads)
, _exec_sem ("io thread exec", 0) , _exec_sem ("io thread exec", 0)
, _idle_sem ("io thread idle", 0) , _idle_sem ("io thread idle", 0)
{ {
assert (n_threads <= hardware_concurrency ()); assert (n_threads <= PBD::hardware_concurrency ());
if (n_threads < 2) { if (n_threads < 2) {
return; return;

View file

@ -610,8 +610,8 @@ LuaBindings::common (lua_State* L)
.addConst ("UseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::UseGroup)) .addConst ("UseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::UseGroup))
.endNamespace () .endNamespace ()
.addFunction ("hardware_concurrency", hardware_concurrency) .addFunction ("hardware_concurrency", PBD::hardware_concurrency)
.addFunction ("max_mmcss_threads_per_process", max_mmcss_threads_per_process) .addFunction ("max_mmcss_threads_per_process", PBD::max_mmcss_threads_per_process)
.endNamespace (); // PBD .endNamespace (); // PBD

View file

@ -718,7 +718,7 @@ ARDOUR::how_many_dsp_threads ()
{ {
/* CALLER MUST HOLD PROCESS LOCK */ /* CALLER MUST HOLD PROCESS LOCK */
int num_cpu = hardware_concurrency(); int num_cpu = PBD::hardware_concurrency();
int pu = Config->get_processor_usage (); int pu = Config->get_processor_usage ();
uint32_t num_threads = max (num_cpu - 1, 2); // default to number of cpus minus one, or 2, whichever is larger uint32_t num_threads = max (num_cpu - 1, 2); // default to number of cpus minus one, or 2, whichever is larger
@ -750,7 +750,7 @@ ARDOUR::how_many_dsp_threads ()
uint32_t uint32_t
ARDOUR::how_many_io_threads () ARDOUR::how_many_io_threads ()
{ {
int num_cpu = hardware_concurrency(); int num_cpu = PBD::hardware_concurrency();
int pu = Config->get_io_thread_count (); int pu = Config->get_io_thread_count ();
uint32_t num_threads = max (num_cpu - 2, 2); uint32_t num_threads = max (num_cpu - 2, 2);
if (pu < 0) { if (pu < 0) {

View file

@ -40,7 +40,7 @@
#endif #endif
int32_t int32_t
max_mmcss_threads_per_process () PBD::max_mmcss_threads_per_process ()
{ {
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
DWORD dwType = REG_DWORD; DWORD dwType = REG_DWORD;
@ -61,7 +61,7 @@ max_mmcss_threads_per_process ()
} }
uint32_t uint32_t
hardware_concurrency() PBD::hardware_concurrency()
{ {
if (getenv("ARDOUR_CONCURRENCY")) { if (getenv("ARDOUR_CONCURRENCY")) {
int c = atoi (getenv("ARDOUR_CONCURRENCY")); int c = atoi (getenv("ARDOUR_CONCURRENCY"));

View file

@ -22,5 +22,9 @@
#include "pbd/libpbd_visibility.h" #include "pbd/libpbd_visibility.h"
namespace PBD{
LIBPBD_API extern uint32_t hardware_concurrency (); LIBPBD_API extern uint32_t hardware_concurrency ();
LIBPBD_API extern int32_t max_mmcss_threads_per_process (); LIBPBD_API extern int32_t max_mmcss_threads_per_process ();
}

View file

@ -342,7 +342,7 @@ WaveViewThreads::start_threads ()
{ {
assert (!_threads.size()); assert (!_threads.size());
const int num_cpus = hardware_concurrency (); const int num_cpus = PBD::hardware_concurrency ();
/* the upper limit of 8 here is entirely arbitrary. It just doesn't /* the upper limit of 8 here is entirely arbitrary. It just doesn't
* seem worthwhile having "ncpus" of low priority threads for * seem worthwhile having "ncpus" of low priority threads for