#include "Rts.h"
#if defined(THREADED_RTS)
-#include "OSThreads.h"
#include "RtsUtils.h"
+#include <windows.h>
/* For reasons not yet clear, the entire contents of process.h is protected
* by __STRICT_ANSI__ not being defined.
void
yieldThread()
{
- Sleep(0);
+ SwitchToThread();
return;
}
shutdownThread()
{
_endthreadex(0);
+ barf("_endthreadex returned"); // avoid gcc warning
}
int
}
}
+void
+freeThreadLocalKey (ThreadLocalKey *key)
+{
+ BOOL r;
+ r = TlsFree(*key);
+ if (r == 0) {
+ DWORD dw = GetLastError();
+ barf("freeThreadLocalKey failed: %lu", dw);
+ }
+}
+
static unsigned __stdcall
forkOS_createThreadWrapper ( void * entry )
(unsigned*)&pId) == 0);
}
+nat
+getNumberOfProcessors (void)
+{
+ static nat nproc = 0;
+
+ if (nproc == 0) {
+ SYSTEM_INFO si;
+ GetSystemInfo(&si);
+ nproc = si.dwNumberOfProcessors;
+ }
+
+ return nproc;
+}
+
+void
+setThreadAffinity (nat n, nat m) // cap N of M
+{
+ 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);
+ }
+}
+
#else /* !defined(THREADED_RTS) */
int