-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Improve thread pool worker thread's spinning for work #13921
Changes from all commits
46801d1
9db86ea
a6344c7
6acb02a
d1af83a
b2ba958
3e09d23
9d21db8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,35 @@ WaitForSingleObject(IN HANDLE hHandle, | |
} | ||
|
||
|
||
/*++ | ||
Function: | ||
WaitForSingleObjectPrioritized | ||
|
||
Similar to WaitForSingleObject, except uses a LIFO release policy for waiting threads by prioritizing new waiters (registering | ||
them at the beginning of the wait queue rather than at the end). | ||
--*/ | ||
DWORD | ||
PALAPI | ||
PAL_WaitForSingleObjectPrioritized(IN HANDLE hHandle, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
why using PAL_ in the name here? I am not seeing aw are doing that in other places There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PAL tries to mimic the Windows API. For functions that are not in that category I believe the convention is to prefix with PAL_. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a bunch of functions that follow this convention, for example https://github.com/dotnet/coreclr/blob/master/src/pal/inc/pal.h#L5393 and others in pal.h There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is it possible we can use WaitForSingleObject with extra parameter instead of adding one more PAL method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to keep the WaitForSingleObject signature in sync with the Windows API |
||
IN DWORD dwMilliseconds) | ||
{ | ||
DWORD dwRet; | ||
|
||
PERF_ENTRY(PAL_WaitForSingleObjectPrioritized); | ||
ENTRY("PAL_WaitForSingleObjectPrioritized(hHandle=%p, dwMilliseconds=%u)\n", | ||
hHandle, dwMilliseconds); | ||
|
||
CPalThread * pThread = InternalGetCurrentThread(); | ||
|
||
dwRet = InternalWaitForMultipleObjectsEx(pThread, 1, &hHandle, FALSE, | ||
dwMilliseconds, FALSE, TRUE /* bPrioritize */); | ||
|
||
LOGEXIT("PAL_WaitForSingleObjectPrioritized returns DWORD %u\n", dwRet); | ||
PERF_EXIT(PAL_WaitForSingleObjectPrioritized); | ||
return dwRet; | ||
} | ||
|
||
|
||
/*++ | ||
Function: | ||
WaitForSingleObjectEx | ||
|
@@ -285,7 +314,8 @@ DWORD CorUnix::InternalWaitForMultipleObjectsEx( | |
CONST HANDLE *lpHandles, | ||
BOOL bWaitAll, | ||
DWORD dwMilliseconds, | ||
BOOL bAlertable) | ||
BOOL bAlertable, | ||
BOOL bPrioritize) | ||
{ | ||
DWORD dwRet = WAIT_FAILED; | ||
PAL_ERROR palErr = NO_ERROR; | ||
|
@@ -530,7 +560,8 @@ DWORD CorUnix::InternalWaitForMultipleObjectsEx( | |
palErr = ppISyncWaitCtrlrs[i]->RegisterWaitingThread( | ||
wtWaitType, | ||
i, | ||
(TRUE == bAlertable)); | ||
(TRUE == bAlertable), | ||
bPrioritize != FALSE); | ||
if (NO_ERROR != palErr) | ||
{ | ||
ERROR("RegisterWaitingThread() failed for %d-th object " | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: couldn't we always assign this to pwtlnCurrFirst before the if rather than assigning it to null here and then to that value in the else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be done either way, both the prev and next need to be assigned on all paths