diff --git a/libs/ardour/luabindings.cc b/libs/ardour/luabindings.cc index 4b8db7f199..683ddeee97 100644 --- a/libs/ardour/luabindings.cc +++ b/libs/ardour/luabindings.cc @@ -22,6 +22,7 @@ #include +#include "pbd/cpus.h" #include "pbd/history_owner.h" #include "pbd/stateful_diff_command.h" #include "pbd/openuri.h" @@ -609,6 +610,9 @@ LuaBindings::common (lua_State* L) .addConst ("UseGroup", PBD::Controllable::GroupControlDisposition(PBD::Controllable::UseGroup)) .endNamespace () + .addFunction ("hardware_concurrency", hardware_concurrency) + .addFunction ("max_mmcss_threads_per_process", max_mmcss_threads_per_process) + .endNamespace (); // PBD luabridge::getGlobalNamespace (L) diff --git a/libs/pbd/cpus.cc b/libs/pbd/cpus.cc index d538697425..6df37441b8 100644 --- a/libs/pbd/cpus.cc +++ b/libs/pbd/cpus.cc @@ -39,6 +39,27 @@ #include // Gets us 'PTW32_VERSION' #endif +int32_t +max_mmcss_threads_per_process () +{ +#ifdef PLATFORM_WINDOWS + DWORD dwType = REG_DWORD; + DWORD dwSize = 4; + int32_t rv = 32; + HKEY hKey; + if (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Multimedia\\SystemProfile", 0, KEY_READ, &hKey)) { + if (ERROR_SUCCESS == RegQueryValueExA (hKey, "MaxThreadsPerProcess", 0, &dwType, (LPBYTE)&rv, &dwSize)) { + if (dwType == REG_DWORD && dwSize == 4) { + return rv; + } + } + } + return 32; +#else + return INT32_MAX; +#endif +} + uint32_t hardware_concurrency() { diff --git a/libs/pbd/pbd/cpus.h b/libs/pbd/pbd/cpus.h index 19b6dc646c..e33aee4d3d 100644 --- a/libs/pbd/pbd/cpus.h +++ b/libs/pbd/pbd/cpus.h @@ -23,4 +23,4 @@ #include "pbd/libpbd_visibility.h" LIBPBD_API extern uint32_t hardware_concurrency (); - +LIBPBD_API extern int32_t max_mmcss_threads_per_process ();