[PATCH] RegisterWaitForSingleObjectX(), fix tmo == 0

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Mon May 3 02:03:09 CDT 2010


Timeout == 0 is special, from the manual:
The time-out interval, in milliseconds. The function returns if the interval
elapses, even if the object's state is nonsignaled. If dwMilliseconds is zero,
the function tests the object's state and returns immediately. If
dwMilliseconds is INFINITE, the function's time-out interval never elapses.

1) Only call Callback iff signaled
2) Implies WT_EXECUTEONLYONCE.
3) Callback should be called before returning.

This is a crude fix not impl. 3) but is enough to get
ies4linux around the 100% CPU problem.
Not sure tmo == 0 implies returning a NULL ptr for phNewWaitObject too.
---
 dlls/ntdll/threadpool.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/dlls/ntdll/threadpool.c b/dlls/ntdll/threadpool.c
index 44afb01..159baee 100644
--- a/dlls/ntdll/threadpool.c
+++ b/dlls/ntdll/threadpool.c
@@ -373,11 +373,17 @@ static DWORD CALLBACK wait_thread_proc(LPVOID Arg)
                     wait_work_item->Context );
                 TimerOrWaitFired = TRUE;
             }
-            wait_work_item->CallbackInProgress = TRUE;
-            wait_work_item->Callback( wait_work_item->Context, TimerOrWaitFired );
-            wait_work_item->CallbackInProgress = FALSE;
+            /* Milliseconds == 0 is special, only call Callback iff
+               signaled and treat as WT_EXECUTEONLYONCE */
+            if (wait_work_item->Milliseconds || !TimerOrWaitFired)
+            {
+        	wait_work_item->CallbackInProgress = TRUE;
+        	wait_work_item->Callback( wait_work_item->Context, TimerOrWaitFired );
+        	wait_work_item->CallbackInProgress = FALSE;
+            }

-            if (wait_work_item->Flags & WT_EXECUTEONLYONCE)
+            if (!wait_work_item->Milliseconds ||
+        	wait_work_item->Flags & WT_EXECUTEONLYONCE)
                 break;
         }
         else
--
1.6.4.4




More information about the wine-devel mailing list