diff --git a/lib/common_defs.h b/lib/common_defs.h index 25501659ee..863a549dcd 100644 --- a/lib/common_defs.h +++ b/lib/common_defs.h @@ -73,6 +73,20 @@ #define MODE_QUIT 6 #define NGRAPHICS_MSGS 7 +// process priorities +// +#define PROCESS_PRIORITY_UNSPECIFIED 0 +#define PROCESS_PRIORITY_LOWEST 1 + // win: IDLE; unix: 19 +#define PROCESS_PRIORITY_LOW 2 + // win: BELOW_NORMAL; unix: 10 +#define PROCESS_PRIORITY_NORMAL 3 + // win: NORMAL; unix: 0 +#define PROCESS_PRIORITY_HIGH 4 + // win: ABOVE_NORMAL; unix: -10 +#define PROCESS_PRIORITY_HIGHEST 5 + // win: HIGH; unix: -16 + // priorities for client messages // #define MSG_INFO 1 diff --git a/lib/proc_control.cpp b/lib/proc_control.cpp index 0eeacb6388..c5f1dea954 100644 --- a/lib/proc_control.cpp +++ b/lib/proc_control.cpp @@ -39,6 +39,7 @@ #endif #endif +#include "common_defs.h" #include "procinfo.h" #include "str_util.h" #include "util.h" @@ -249,3 +250,27 @@ void suspend_or_resume_process(int pid, bool resume) { ::kill(pid, resume?SIGCONT:SIGSTOP); #endif } + +// return OS-specific value associated with priority code +// +int process_priority_value(int priority) { +#ifdef _WIN32 + switch (priority) { + case PROCESS_PRIORITY_LOWEST: return IDLE_PRIORITY_CLASS; + case PROCESS_PRIORITY_LOW: return BELOW_NORMAL_PRIORITY_CLASS; + case PROCESS_PRIORITY_NORMAL: return NORMAL_PRIORITY_CLASS; + case PROCESS_PRIORITY_HIGH: return ABOVE_NORMAL_PRIORITY_CLASS; + case PROCESS_PRIORITY_HIGHEST: return HIGH_PRIORITY_CLASS; + } + return 0; +#else + switch (priority) { + case PROCESS_PRIORITY_LOWEST: return 19; + case PROCESS_PRIORITY_LOW: return 10; + case PROCESS_PRIORITY_NORMAL: return 0; + case PROCESS_PRIORITY_HIGH: return -10; + case PROCESS_PRIORITY_HIGHEST: return -16; + } + return 0; +#endif +} diff --git a/lib/proc_control.h b/lib/proc_control.h index 7dd84308c0..0b3f547007 100644 --- a/lib/proc_control.h +++ b/lib/proc_control.h @@ -37,4 +37,6 @@ extern void kill_descendants(int child_pid=0); extern void suspend_or_resume_descendants(bool resume); extern void suspend_or_resume_process(int pid, bool resume); +extern int process_priority_value(int); + #endif diff --git a/samples/wrapper/wrapper.cpp b/samples/wrapper/wrapper.cpp index 4ed8c71f1f..55776d47f1 100644 --- a/samples/wrapper/wrapper.cpp +++ b/samples/wrapper/wrapper.cpp @@ -125,7 +125,7 @@ struct TASK { bool append_cmdline_args; bool multi_process; double time_limit; - bool no_priority_change; + int priority; // dynamic stuff follows double current_cpu_time; @@ -381,7 +381,7 @@ int TASK::parse(XML_PARSER& xp) { multi_process = false; append_cmdline_args = false; time_limit = 0; - no_priority_change = false; + priority = PROCESS_PRIORITY_LOWEST; while (!xp.get_tag()) { if (!xp.is_tag) { @@ -419,7 +419,7 @@ int TASK::parse(XML_PARSER& xp) { else if (xp.parse_bool("multi_process", multi_process)) continue; else if (xp.parse_bool("append_cmdline_args", append_cmdline_args)) continue; else if (xp.parse_double("time_limit", time_limit)) continue; - else if (xp.parse_bool("no_priority_change", no_priority_change)) continue; + else if (xp.parse_int("priority", priority)) continue; } return ERR_XML_PARSE; } @@ -697,7 +697,7 @@ int TASK::run(int argct, char** argvt) { NULL, NULL, TRUE, // bInheritHandles - CREATE_NO_WINDOW|(no_priority_change?0:IDLE_PRIORITY_CLASS), + CREATE_NO_WINDOW|process_priority_value(priority), (LPVOID) env_vars, exec_dir.empty()?NULL:exec_dir.c_str(), &startup_info, @@ -772,9 +772,7 @@ int TASK::run(int argct, char** argvt) { argv[0] = app_path; strlcpy(arglist, command_line.c_str(), sizeof(arglist)); parse_command_line(arglist, argv+1); - if (!no_priority_change) { - setpriority(PRIO_PROCESS, 0, PROCESS_IDLE_PRIORITY); - } + setpriority(PRIO_PROCESS, 0, process_priority_value(priority)); if (!exec_dir.empty()) { retval = chdir(exec_dir.c_str()); if (!retval) { diff --git a/win_build/wrapper.vcxproj b/win_build/wrapper.vcxproj index 926786d832..e50894b4b9 100644 --- a/win_build/wrapper.vcxproj +++ b/win_build/wrapper.vcxproj @@ -90,6 +90,7 @@ wrapper_26011_windows_x86_64 wrapper_26011_windows_intelx86 + wrapper_6.1_windows_x86_64