| @@ -13,6 +13,8 @@ bool isDirectory(const std::string &path); | |||||
| void copyFile(const std::string &srcPath, const std::string &destPath); | void copyFile(const std::string &srcPath, const std::string &destPath); | ||||
| void createDirectory(const std::string &path); | void createDirectory(const std::string &path); | ||||
| /** Currently this lies and returns the number of logical cores instead. */ | |||||
| int getPhysicalCoreCount(); | |||||
| void setThreadName(const std::string &name); | void setThreadName(const std::string &name); | ||||
| /** Opens a URL, also happens to work with PDFs and folders. | /** Opens a URL, also happens to work with PDFs and folders. | ||||
| @@ -299,6 +299,35 @@ struct SampleRateItem : MenuItem { | |||||
| }; | }; | ||||
| struct ThreadCountValueItem : MenuItem { | |||||
| int threadCount; | |||||
| ThreadCountValueItem(int threadCount) { | |||||
| this->threadCount = threadCount; | |||||
| text = string::f("%d", threadCount); | |||||
| rightText = CHECKMARK(app()->engine->threadCount == threadCount); | |||||
| } | |||||
| void onAction(const event::Action &e) override { | |||||
| app()->engine->threadCount = threadCount; | |||||
| } | |||||
| }; | |||||
| struct ThreadCount : MenuItem { | |||||
| ThreadCount() { | |||||
| text = "Thread count"; | |||||
| } | |||||
| Menu *createChildMenu() override { | |||||
| Menu *menu = new Menu; | |||||
| int coreCount = system::getPhysicalCoreCount(); | |||||
| for (int i = 1; i <= coreCount; i++) { | |||||
| menu->addChild(new ThreadCountValueItem(i)); | |||||
| } | |||||
| return menu; | |||||
| } | |||||
| }; | |||||
| struct FullscreenItem : MenuItem { | struct FullscreenItem : MenuItem { | ||||
| FullscreenItem() { | FullscreenItem() { | ||||
| text = "Fullscreen"; | text = "Fullscreen"; | ||||
| @@ -325,6 +354,7 @@ struct SettingsButton : MenuButton { | |||||
| menu->addChild(new PowerMeterItem); | menu->addChild(new PowerMeterItem); | ||||
| menu->addChild(new LockModulesItem); | menu->addChild(new LockModulesItem); | ||||
| menu->addChild(new SampleRateItem); | menu->addChild(new SampleRateItem); | ||||
| menu->addChild(new ThreadCount); | |||||
| menu->addChild(new FullscreenItem); | menu->addChild(new FullscreenItem); | ||||
| Slider *zoomSlider = new Slider; | Slider *zoomSlider = new Slider; | ||||
| @@ -68,6 +68,9 @@ static json_t *settingsToJson() { | |||||
| // powerMeter | // powerMeter | ||||
| json_object_set_new(rootJ, "powerMeter", json_boolean(powerMeter)); | json_object_set_new(rootJ, "powerMeter", json_boolean(powerMeter)); | ||||
| // threadCount | |||||
| json_object_set_new(rootJ, "threadCount", json_integer(app()->engine->threadCount)); | |||||
| // checkVersion | // checkVersion | ||||
| json_object_set_new(rootJ, "checkVersion", json_boolean(checkVersion)); | json_object_set_new(rootJ, "checkVersion", json_boolean(checkVersion)); | ||||
| @@ -146,6 +149,11 @@ static void settingsFromJson(json_t *rootJ) { | |||||
| if (powerMeterJ) | if (powerMeterJ) | ||||
| powerMeter = json_boolean_value(powerMeterJ); | powerMeter = json_boolean_value(powerMeterJ); | ||||
| // threadCount | |||||
| json_t *threadCountJ = json_object_get(rootJ, "threadCount"); | |||||
| if (threadCountJ) | |||||
| app()->engine->threadCount = json_integer_value(threadCountJ); | |||||
| // checkVersion | // checkVersion | ||||
| json_t *checkVersionJ = json_object_get(rootJ, "checkVersion"); | json_t *checkVersionJ = json_object_get(rootJ, "checkVersion"); | ||||
| if (checkVersionJ) | if (checkVersionJ) | ||||
| @@ -1,4 +1,5 @@ | |||||
| #include "system.hpp" | #include "system.hpp" | ||||
| #include <thread> | |||||
| #include <dirent.h> | #include <dirent.h> | ||||
| #include <sys/stat.h> | #include <sys/stat.h> | ||||
| @@ -77,6 +78,11 @@ void createDirectory(const std::string &path) { | |||||
| #endif | #endif | ||||
| } | } | ||||
| int getPhysicalCoreCount() { | |||||
| // TODO Return the physical cores, not logical cores. | |||||
| return std::thread::hardware_concurrency(); | |||||
| } | |||||
| void setThreadName(const std::string &name) { | void setThreadName(const std::string &name) { | ||||
| #if defined ARCH_LIN | #if defined ARCH_LIN | ||||
| pthread_setname_np(pthread_self(), name.c_str()); | pthread_setname_np(pthread_self(), name.c_str()); | ||||