add thread priority option (using QThread)

This commit is contained in:
WarmUpTill
2020-06-06 15:14:08 +02:00
parent 7fef29dafb
commit f03fca85aa
7 changed files with 101 additions and 36 deletions

View File

@@ -3,7 +3,6 @@
#include <chrono>
#include <string>
#include <vector>
#include <thread>
#include <regex>
#include <mutex>
#include <fstream>
@@ -256,7 +255,7 @@ typedef enum { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 } NoMatch;
* SwitcherData
********************************************************************************/
struct SwitcherData {
thread th;
QThread* th = nullptr;
condition_variable cv;
mutex m;
bool transitionActive = false;
@@ -311,18 +310,33 @@ struct SwitcherData {
DEFAULT_PRIORITY_3, DEFAULT_PRIORITY_4, DEFAULT_PRIORITY_5,
DEFAULT_PRIORITY_6, DEFAULT_PRIORITY_7};
std::vector<std::string> threadPrioritiesNamesOrderdByPrio{
"Lowest", "Low", "Normal", "High", "Highest", "Time critical",
struct ThreadPrio {
std::string name;
std::string description;
uint32_t value;
};
std::map<std::string, int> threadPriorities = {
{"Lowest", QThread::LowestPriority},
{"Low", QThread::LowPriority},
{"Normal", QThread::NormalPriority},
{"High", QThread::HighPriority},
{"Highest", QThread::HighestPriority},
{"Time critical", QThread::TimeCriticalPriority},
std::vector<ThreadPrio> threadPriorities{
{"Idle",
"scheduled only when no other threads are running (lowest CPU load)",
QThread::IdlePriority},
{"Lowest", "scheduled less often than LowPriority",
QThread::LowestPriority},
{"Low", "scheduled less often than NormalPriority",
QThread::LowPriority},
{"Normal", "the default priority of the operating system",
QThread::NormalPriority},
{"High", "scheduled more often than NormalPriority",
QThread::HighPriority},
{"Highest", "scheduled more often than HighPriority",
QThread::HighestPriority},
{"Time critical",
"scheduled as often as possible (highest CPU load)",
QThread::TimeCriticalPriority},
};
uint32_t threadPriority = QThread::NormalPriority;
void Thread();
void Start();
void Stop();