Skip to content

Commit

Permalink
[wip] kernel32: ThreadIdealProcessor
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Krakow <[email protected]>
  • Loading branch information
kakra committed Feb 23, 2019
1 parent d22d137 commit ac7c46a
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions dlls/kernel32/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#ifdef HAVE_SYS_PRCTL_H
# include <sys/prctl.h>
#endif
#ifdef HAVE_SCHED_H
# include <sched.h>
#endif

#include "ntstatus.h"
#define WIN32_NO_STATUS
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)<<processor->Number) == 0)
return FALSE;

return TRUE;
}

Expand All @@ -627,13 +635,37 @@ 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
int res = sched_getcpu();

static int once = 0;
if (!once++)
FIXME("(%p, %d) using sched_getcpu()\n", hThread, dwIdealProcessor);

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;
}

/***********************************************************************
Expand Down

0 comments on commit ac7c46a

Please sign in to comment.