void
yieldThread()
{
- Sleep(0);
+ SwitchToThread();
return;
}
}
void
-setThreadAffinity (nat n STG_UNUSED, nat m STG_UNUSED)
+setThreadAffinity (nat n, nat m) // cap N of M
{
- /* ToDo */
+ HANDLE hThread;
+ DWORD_PTR mask, r; // 64-bit win is required to handle more than 32 procs
+ nat nproc, i;
+
+ hThread = GetCurrentThread();
+
+ nproc = getNumberOfProcessors();
+
+ mask = 0;
+ for (i = n; i < nproc; i+=m) {
+ mask |= 1 << i;
+ }
+
+ r = SetThreadAffinityMask(hThread, mask);
+ if (r == 0) {
+ sysErrorBelch("SetThreadAffinity");
+ stg_exit(EXIT_FAILURE);
+ }
+}
+
+typedef BOOL (WINAPI *PCSIO)(HANDLE);
+
+void
+interruptOSThread (OSThreadId id)
+{
+ HANDLE hdl;
+ PCSIO pCSIO;
+ if (!(hdl = OpenThread(THREAD_TERMINATE,FALSE,id))) {
+ sysErrorBelch("interruptOSThread: OpenThread");
+ stg_exit(EXIT_FAILURE);
+ }
+ pCSIO = (PCSIO) GetProcAddress(GetModuleHandle(TEXT("Kernel32.dll")), "CancelSynchronousIo");
+ if ( NULL != pCSIO ) {
+ pCSIO(hdl);
+ } else {
+ // Nothing to do, unfortunately
+ }
}
#else /* !defined(THREADED_RTS) */