Skip to content

Commit e5af4ac

Browse files
PlatformMisc: add SetProcessAffinity and GetProcessAffinity
1 parent 5f29e3b commit e5af4ac

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

Platforms/Basic/interface/BasicPlatformMisc.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -111,6 +111,13 @@ struct BasicPlatformMisc
111111
/// Sets the current thread affinity mask and on success returns the previous mask.
112112
static Uint64 SetCurrentThreadAffinity(Uint64 Mask);
113113

114+
/// Sets the current process affinity mask.
115+
/// On success, returns true. On failure, returns false and the affinity mask is not changed.
116+
static Bool SetProcessAffinity(Uint64 Mask);
117+
118+
/// Returns the current process affinity mask. On failure, returns 0.
119+
static Uint64 GetProcessAffinity();
120+
114121
/// Sets the name of the current thread.
115122
static void SetCurrentThreadName(const char* Name);
116123

Platforms/Basic/src/BasicPlatformMisc.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,6 +48,18 @@ Uint64 BasicPlatformMisc::SetCurrentThreadAffinity(Uint64 Mask)
4848
return 0;
4949
}
5050

51+
Bool BasicPlatformMisc::SetProcessAffinity(Uint64 Mask)
52+
{
53+
LOG_WARNING_MESSAGE_ONCE("SetProcessAffinity is not implemented on this platform.");
54+
return false;
55+
}
56+
57+
Uint64 BasicPlatformMisc::GetProcessAffinity()
58+
{
59+
LOG_WARNING_MESSAGE_ONCE("GetProcessAffinity is not implemented on this platform.");
60+
return 0;
61+
}
62+
5163
void BasicPlatformMisc::SetCurrentThreadName(const char* Name)
5264
{
5365
LOG_WARNING_MESSAGE_ONCE("SetCurrentThreadName is not implemented on this platform.");

Platforms/Win32/interface/Win32PlatformMisc.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -168,6 +168,13 @@ struct WindowsMisc : public BasicPlatformMisc
168168
/// On failure, returns 0.
169169
static Uint64 SetCurrentThreadAffinity(Uint64 Mask);
170170

171+
/// Sets the current process affinity mask.
172+
/// On success, returns true. On failure, returns false and the affinity mask is not changed.
173+
static Bool SetProcessAffinity(Uint64 Mask);
174+
175+
/// Returns the process affinity mask. On failure, returns 0.
176+
static Uint64 GetProcessAffinity();
177+
171178
static ThreadPriority GetCurrentThreadPriority();
172179

173180
/// Sets the current thread priority and on success returns the previous priority.

Platforms/Win32/src/Win32PlatformMisc.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,22 @@ Uint64 WindowsMisc::SetCurrentThreadAffinity(Uint64 Mask)
4343
return SetThreadAffinityMask(hCurrThread, static_cast<DWORD_PTR>(Mask));
4444
}
4545

46+
Bool WindowsMisc::SetProcessAffinity(Uint64 Mask)
47+
{
48+
const HANDLE hCurrProcess = GetCurrentProcess();
49+
return SetProcessAffinityMask(hCurrProcess, static_cast<DWORD_PTR>(Mask)) != 0;
50+
}
51+
52+
Uint64 WindowsMisc::GetProcessAffinity()
53+
{
54+
DWORD_PTR ProcessAffinityMask = 0;
55+
DWORD_PTR SystemAffinityMask = 0;
56+
const HANDLE hCurrProcess = GetCurrentProcess();
57+
if (GetProcessAffinityMask(hCurrProcess, &ProcessAffinityMask, &SystemAffinityMask))
58+
return static_cast<Uint64>(ProcessAffinityMask);
59+
else
60+
return 0;
61+
}
4662

4763
static ThreadPriority WndPriorityToThreadPiority(int priority)
4864
{

0 commit comments

Comments
 (0)