From bb17a5b2305dde4eb9daf3d89374e6f2248a6826 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Thu, 11 Oct 2018 05:47:50 +0200 Subject: [PATCH] [wip] kernel32: ThreadIdealProcessor Signed-off-by: Kai Krakow --- dlls/kernel32/thread.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/dlls/kernel32/thread.c b/dlls/kernel32/thread.c index 61186339fa0..1b540457a0e 100644 --- a/dlls/kernel32/thread.c +++ b/dlls/kernel32/thread.c @@ -31,6 +31,9 @@ #ifdef HAVE_SYS_PRCTL_H # include #endif +#ifdef HAVE_SCHED_H +# include +#endif #include "ntstatus.h" #define WIN32_NO_STATUS @@ -598,7 +601,7 @@ DWORD_PTR WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD_PTR dwThreadAffini */ BOOL WINAPI SetThreadIdealProcessorEx(HANDLE thread, PROCESSOR_NUMBER *processor, PROCESSOR_NUMBER *previous) { - FIXME("(%p, %p, %p): stub\n", thread, processor, previous); + FIXME("(%p, %p)->(%p)\n", thread, processor, previous); if (!processor || processor->Group > 0 || processor->Number > MAXIMUM_PROCESSORS) { @@ -609,10 +612,15 @@ BOOL WINAPI SetThreadIdealProcessorEx(HANDLE thread, PROCESSOR_NUMBER *processor if (previous) { previous->Group = 0; - previous->Number = 0; + previous->Number = SetThreadIdealProcessor(thread, MAXIMUM_PROCESSORS); previous->Reserved = 0; + if (previous->Number != 0) + return 0; } + if (SetThreadAffinityMask(thread, ((DWORD_PTR)1)<Number) == 0) + return FALSE; + return TRUE; } @@ -627,13 +635,36 @@ DWORD WINAPI SetThreadIdealProcessor( HANDLE hThread, /* [in] Specifies the thread of interest */ DWORD dwIdealProcessor) /* [in] Specifies the new preferred processor */ { - FIXME("(%p): stub\n",hThread); + struct _PROCESSOR_NUMBER ideal; + + TRACE("(%p, %d)\n", hThread, dwIdealProcessor); + if (dwIdealProcessor > MAXIMUM_PROCESSORS) { SetLastError(ERROR_INVALID_PARAMETER); return ~0u; } - return 0; + + if (dwIdealProcessor == MAXIMUM_PROCESSORS) + { +#ifdef HAVE_SCHED_H + static int once = 0; + if (!once++) + FIXME("(%p, %d) using sched_getcpu()\n", hThread, dwIdealProcessor); + + int res = sched_getcpu(); + if (res != -1) + return res; +#endif + SetLastError(ERROR_INVALID_PARAMETER); + return ~0u; + } + + ideal.Group = 0; + ideal.Number = dwIdealProcessor; + ideal.Reserved = 0; + + return SetThreadIdealProcessorEx(hThread, &ideal, &ideal) == 0 ? ~0u : ideal.Number; } /***********************************************************************