Browse Source

Add Engine::threadCount to toolbar menu and settings.json

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
557460b194
4 changed files with 46 additions and 0 deletions
  1. +2
    -0
      include/system.hpp
  2. +30
    -0
      src/app/Toolbar.cpp
  3. +8
    -0
      src/settings.cpp
  4. +6
    -0
      src/system.cpp

+ 2
- 0
include/system.hpp View File

@@ -13,6 +13,8 @@ bool isDirectory(const std::string &path);
void copyFile(const std::string &srcPath, const std::string &destPath);
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);

/** Opens a URL, also happens to work with PDFs and folders.


+ 30
- 0
src/app/Toolbar.cpp View File

@@ -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 {
FullscreenItem() {
text = "Fullscreen";
@@ -325,6 +354,7 @@ struct SettingsButton : MenuButton {
menu->addChild(new PowerMeterItem);
menu->addChild(new LockModulesItem);
menu->addChild(new SampleRateItem);
menu->addChild(new ThreadCount);
menu->addChild(new FullscreenItem);

Slider *zoomSlider = new Slider;


+ 8
- 0
src/settings.cpp View File

@@ -68,6 +68,9 @@ static json_t *settingsToJson() {
// powerMeter
json_object_set_new(rootJ, "powerMeter", json_boolean(powerMeter));

// threadCount
json_object_set_new(rootJ, "threadCount", json_integer(app()->engine->threadCount));

// checkVersion
json_object_set_new(rootJ, "checkVersion", json_boolean(checkVersion));

@@ -146,6 +149,11 @@ static void settingsFromJson(json_t *rootJ) {
if (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
json_t *checkVersionJ = json_object_get(rootJ, "checkVersion");
if (checkVersionJ)


+ 6
- 0
src/system.cpp View File

@@ -1,4 +1,5 @@
#include "system.hpp"
#include <thread>
#include <dirent.h>
#include <sys/stat.h>

@@ -77,6 +78,11 @@ void createDirectory(const std::string &path) {
#endif
}

int getPhysicalCoreCount() {
// TODO Return the physical cores, not logical cores.
return std::thread::hardware_concurrency();
}

void setThreadName(const std::string &name) {
#if defined ARCH_LIN
pthread_setname_np(pthread_self(), name.c_str());


Loading…
Cancel
Save