1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 04:02:42 +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
}
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)
{
#ifdef _WIN32
@ -2441,12 +2465,7 @@ void thread_ctrl::set_thread_affinity_mask(u64 mask)
u64 thread_ctrl::get_thread_affinity_mask()
{
#ifdef _WIN32
DWORD_PTR res, _sys;
if (!GetProcessAffinityMask(GetCurrentProcess(), &res, &_sys))
{
sig_log.error("Failed to get process affinity mask.");
return 0;
}
const u64 res = get_process_affinity_mask();
if (DWORD_PTR result = SetThreadAffinityMask(GetCurrentThread(), res))
{

View File

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