aboutsummaryrefslogtreecommitdiff
path: root/src/common/Threading/ProcessPriority.h
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2017-05-11 22:29:51 +0200
committerShauren <shauren.trinity@gmail.com>2017-05-11 22:29:51 +0200
commit3a418a0bbc8e155e5395595c5e25c038d3c7c773 (patch)
tree45359566bd6e360dd133e7ef43bc2a42e26baf56 /src/common/Threading/ProcessPriority.h
parent8abc56c540b5d2c583e40ad3d302c43068778ed1 (diff)
Core/Common: Include cleanup
Diffstat (limited to 'src/common/Threading/ProcessPriority.h')
-rw-r--r--src/common/Threading/ProcessPriority.h84
1 files changed, 5 insertions, 79 deletions
diff --git a/src/common/Threading/ProcessPriority.h b/src/common/Threading/ProcessPriority.h
index b4ff3f5ecf6..3cb866c7de1 100644
--- a/src/common/Threading/ProcessPriority.h
+++ b/src/common/Threading/ProcessPriority.h
@@ -18,86 +18,12 @@
#ifndef _PROCESSPRIO_H
#define _PROCESSPRIO_H
-#include "Configuration/Config.h"
+#include "Define.h"
+#include <string>
-#ifdef __linux__
-#include <sched.h>
-#include <sys/resource.h>
-#define PROCESS_HIGH_PRIORITY -15 // [-20, 19], default is 0
-#endif
-
-void SetProcessPriority(const std::string& logChannel)
-{
-#if defined(_WIN32) || defined(__linux__)
-
- ///- Handle affinity for multiple processors and process priority
- uint32 affinity = sConfigMgr->GetIntDefault("UseProcessors", 0);
- bool highPriority = sConfigMgr->GetBoolDefault("ProcessPriority", false);
-
-#ifdef _WIN32 // Windows
-
- HANDLE hProcess = GetCurrentProcess();
- if (affinity > 0)
- {
- ULONG_PTR appAff;
- ULONG_PTR sysAff;
-
- if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
- {
- // remove non accessible processors
- ULONG_PTR currentAffinity = affinity & appAff;
-
- if (!currentAffinity)
- TC_LOG_ERROR(logChannel, "Processors marked in UseProcessors bitmask (hex) %x are not accessible. Accessible processors bitmask (hex): %x", affinity, appAff);
- else if (SetProcessAffinityMask(hProcess, currentAffinity))
- TC_LOG_INFO(logChannel, "Using processors (bitmask, hex): %x", currentAffinity);
- else
- TC_LOG_ERROR(logChannel, "Can't set used processors (hex): %x", currentAffinity);
- }
- }
-
- if (highPriority)
- {
- if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
- TC_LOG_INFO(logChannel, "Process priority class set to HIGH");
- else
- TC_LOG_ERROR(logChannel, "Can't set process priority class.");
- }
+#define CONFIG_PROCESSOR_AFFINITY "UseProcessors"
+#define CONFIG_HIGH_PRIORITY "ProcessPriority"
-#else // Linux
-
- if (affinity > 0)
- {
- cpu_set_t mask;
- CPU_ZERO(&mask);
-
- for (unsigned int i = 0; i < sizeof(affinity) * 8; ++i)
- if (affinity & (1 << i))
- CPU_SET(i, &mask);
-
- if (sched_setaffinity(0, sizeof(mask), &mask))
- TC_LOG_ERROR(logChannel, "Can't set used processors (hex): %x, error: %s", affinity, strerror(errno));
- else
- {
- CPU_ZERO(&mask);
- sched_getaffinity(0, sizeof(mask), &mask);
- TC_LOG_INFO(logChannel, "Using processors (bitmask, hex): %lx", *(__cpu_mask*)(&mask));
- }
- }
-
- if (highPriority)
- {
- if (setpriority(PRIO_PROCESS, 0, PROCESS_HIGH_PRIORITY))
- TC_LOG_ERROR(logChannel, "Can't set process priority class, error: %s", strerror(errno));
- else
- TC_LOG_INFO(logChannel, "Process priority class set to %i", getpriority(PRIO_PROCESS, 0));
- }
-
-#endif
-#else
- // Suppresses unused argument warning for all other platforms
- (void)logChannel;
-#endif
-}
+void TC_COMMON_API SetProcessPriority(std::string const& logChannel, uint32 affinity, bool highPriority);
#endif