Dreamine.Threading.Windows
1.0.1
이 패키지는 다른 어셈블리에서 `DMContainer`를 partial class로 확장하지 않습니다. 등록은 별도의 Registration 클래스를 통해 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
WindowsThreadAffinityService.cs
이 파일의 문서화 페이지로 가기
1
using
System.ComponentModel;
2
using
Dreamine.Threading.Interfaces;
3
using
Dreamine.Threading.Windows.Native
;
4
5
namespace
Dreamine.Threading.Windows.Services
;
6
15
public
sealed
class
WindowsThreadAffinityService
: IThreadAffinityService
16
{
57
public
void
ApplyToCurrentThread
(
int
coreIndex)
58
{
59
if
(coreIndex < 0)
60
{
61
throw
new
ArgumentOutOfRangeException(nameof(coreIndex),
"CPU core index cannot be negative."
);
62
}
63
64
if
(coreIndex >= IntPtr.Size * 8)
65
{
66
throw
new
ArgumentOutOfRangeException(
67
nameof(coreIndex),
68
$
"CPU core index {coreIndex} exceeds the affinity mask width."
);
69
}
70
71
var mask =
new
UIntPtr(1UL << coreIndex);
72
var currentThread = Kernel32NativeMethods.GetCurrentThread();
73
74
var previousMask = Kernel32NativeMethods.SetThreadAffinityMask(currentThread, mask);
75
76
if
(previousMask == UIntPtr.Zero)
77
{
78
throw
new
Win32Exception(
79
System.Runtime.InteropServices.Marshal.GetLastWin32Error(),
80
$
"Failed to set thread affinity. CoreIndex={coreIndex}"
);
81
}
82
}
83
100
public
void
ClearCurrentThreadAffinity
()
101
{
102
/*
103
* Windows SetThreadAffinityMask requires a valid mask.
104
* Restoring the original process-wide scheduling behavior requires the previous
105
* affinity mask to be stored per thread.
106
*
107
* The current Core interface does not expose a restore token, so this method is
108
* intentionally a no-op for now.
109
*
110
* Future improvement:
111
* - Change IThreadAffinityService.ApplyToCurrentThread to return a restore handle.
112
* - Restore the previous affinity mask in Clear/Dispose.
113
*/
114
}
115
}
Dreamine.Threading.Windows.Native
Definition
Kernel32NativeMethods.cs:4
Dreamine.Threading.Windows.Services
Definition
WindowsCpuInfoProvider.cs:3
Dreamine.Threading.Windows.Services.WindowsThreadAffinityService
Definition
WindowsThreadAffinityService.cs:16
Dreamine.Threading.Windows.Services.WindowsThreadAffinityService.ClearCurrentThreadAffinity
void ClearCurrentThreadAffinity()
Definition
WindowsThreadAffinityService.cs:100
Dreamine.Threading.Windows.Services.WindowsThreadAffinityService.ApplyToCurrentThread
void ApplyToCurrentThread(int coreIndex)
Definition
WindowsThreadAffinityService.cs:57
Services
WindowsThreadAffinityService.cs
다음에 의해 생성됨 :
1.17.0