1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Implement thread_ctrl::get_process_affinity_mask()

This commit is contained in:
Nekotekina 2020-04-29 22:11:59 +03:00
parent c1bd154bcd
commit f6200ba635
2 changed files with 32 additions and 6 deletions

View File

@ -2399,6 +2399,30 @@ void thread_ctrl::set_native_priority(int priority)
#endif #endif
} }
u64 thread_ctrl::get_process_affinity_mask()
{
static const u64 mask = []() -> u64
{
#ifdef _WIN32
DWORD_PTR res, _sys;
if (!GetProcessAffinityMask(GetCurrentProcess(), &res, &_sys))
{
sig_log.error("Failed to get process affinity mask.");
return 0;
}
return res;
#else
// Assume it's called from the main thread (this is a bit shaky)
return thread_ctrl::get_thread_affinity_mask();
#endif
}();
return mask;
}
DECLARE(thread_ctrl::process_affinity_mask) = get_process_affinity_mask();
void thread_ctrl::set_thread_affinity_mask(u64 mask) void thread_ctrl::set_thread_affinity_mask(u64 mask)
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -2441,12 +2465,7 @@ void thread_ctrl::set_thread_affinity_mask(u64 mask)
u64 thread_ctrl::get_thread_affinity_mask() u64 thread_ctrl::get_thread_affinity_mask()
{ {
#ifdef _WIN32 #ifdef _WIN32
DWORD_PTR res, _sys; const u64 res = get_process_affinity_mask();
if (!GetProcessAffinityMask(GetCurrentProcess(), &res, &_sys))
{
sig_log.error("Failed to get process affinity mask.");
return 0;
}
if (DWORD_PTR result = SetThreadAffinityMask(GetCurrentThread(), res)) if (DWORD_PTR result = SetThreadAffinityMask(GetCurrentThread(), res))
{ {

View File

@ -249,8 +249,15 @@ public:
// Sets the preferred affinity mask for this thread // Sets the preferred affinity mask for this thread
static void set_thread_affinity_mask(u64 mask); static void set_thread_affinity_mask(u64 mask);
// Get process affinity mask
static u64 get_process_affinity_mask();
// Miscellaneous // Miscellaneous
static u64 get_thread_affinity_mask(); static u64 get_thread_affinity_mask();
private:
// Miscellaneous
static const u64 process_affinity_mask;
}; };
// Derived from the callable object Context, possibly a lambda // Derived from the callable object Context, possibly a lambda