AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ProcessPriority.h File Reference
#include "Define.h"
#include <string>

Go to the source code of this file.

Macros

#define CONFIG_PROCESSOR_AFFINITY   "UseProcessors"
 
#define CONFIG_HIGH_PRIORITY   "ProcessPriority"
 

Functions

void AC_COMMON_API SetProcessPriority (std::string const &logChannel, uint32 affinity, bool highPriority)
 

Macro Definition Documentation

◆ CONFIG_HIGH_PRIORITY

#define CONFIG_HIGH_PRIORITY   "ProcessPriority"

◆ CONFIG_PROCESSOR_AFFINITY

#define CONFIG_PROCESSOR_AFFINITY   "UseProcessors"

Function Documentation

◆ SetProcessPriority()

void AC_COMMON_API SetProcessPriority ( std::string const &  logChannel,
uint32  affinity,
bool  highPriority 
)
  • Handle affinity for multiple processors and process priority
30{
32#ifdef _WIN32 // Windows
33
34 HANDLE hProcess = GetCurrentProcess();
35 if (affinity > 0)
36 {
37 ULONG_PTR appAff;
38 ULONG_PTR sysAff;
39
40 if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
41 {
42 // remove non accessible processors
43 ULONG_PTR currentAffinity = affinity & appAff;
44
45 if (!currentAffinity)
46 {
47 LOG_ERROR(logChannel, "Processors marked in UseProcessors bitmask (hex) {:x} are not accessible. Accessible processors bitmask (hex): {:x}", affinity, appAff);
48 }
49 else if (SetProcessAffinityMask(hProcess, currentAffinity))
50 {
51 LOG_INFO(logChannel, "Using processors (bitmask, hex): {:x}", currentAffinity);
52 }
53 else
54 {
55 LOG_ERROR(logChannel, "Can't set used processors (hex): {:x}", currentAffinity);
56 }
57 }
58 }
59
60 if (highPriority)
61 {
62 if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
63 {
64 LOG_INFO(logChannel, "Process priority class set to HIGH");
65 }
66 else
67 {
68 LOG_ERROR(logChannel, "Can't set process priority class.");
69 }
70 }
71
72#elif defined(__linux__) // Linux
73
74 if (affinity > 0)
75 {
76 cpu_set_t mask;
77 CPU_ZERO(&mask);
78
79 for (unsigned int i = 0; i < sizeof(affinity) * 8; ++i)
80 if (affinity & (1 << i))
81 {
82 CPU_SET(i, &mask);
83 }
84
85 if (sched_setaffinity(0, sizeof(mask), &mask))
86 {
87 LOG_ERROR(logChannel, "Can't set used processors (hex): {:x}, error: {}", affinity, strerror(errno));
88 }
89 else
90 {
91 CPU_ZERO(&mask);
92 sched_getaffinity(0, sizeof(mask), &mask);
93 LOG_INFO(logChannel, "Using processors (bitmask, hex): {:x}", *(__cpu_mask*)(&mask));
94 }
95 }
96
97 if (highPriority)
98 {
99 if (setpriority(PRIO_PROCESS, 0, PROCESS_HIGH_PRIORITY))
100 {
101 LOG_ERROR(logChannel, "Can't set process priority class, error: {}", strerror(errno));
102 }
103 else
104 {
105 LOG_INFO(logChannel, "Process priority class set to {}", getpriority(PRIO_PROCESS, 0));
106 }
107 }
108
109#else
110 // Suppresses unused argument warning for all other platforms
111 (void)logChannel;
112 (void)affinity;
113 (void)highPriority;
114#endif
115}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157

References LOG_ERROR, and LOG_INFO.

Referenced by main().