Module: wine Branch: master Commit: 7b7d8374a40ddae124cdd089e2eedb32e11b9f03 URL: http://source.winehq.org/git/wine.git/?a=commit;h=7b7d8374a40ddae124cdd089e2...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Mon Sep 1 10:40:42 2014 +0400
ntdll: NtWaitForMultipleObjects()'s third arguments means 'wait_any', not 'wait_all'.
---
dlls/kernel32/sync.c | 2 +- dlls/kernel32/tests/sync.c | 28 +++++++++++++++++++++++++--- dlls/ntdll/sync.c | 4 ++-- dlls/ntdll/threadpool.c | 2 +- 4 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/dlls/kernel32/sync.c b/dlls/kernel32/sync.c index 8379c1d..d399b82 100644 --- a/dlls/kernel32/sync.c +++ b/dlls/kernel32/sync.c @@ -185,7 +185,7 @@ DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, } }
- status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, + status = NtWaitForMultipleObjects( count, hloc, !wait_all, alertable, get_nt_timeout( &time, timeout ) );
if (HIWORD(status)) /* is it an error code? */ diff --git a/dlls/kernel32/tests/sync.c b/dlls/kernel32/tests/sync.c index 2381302..cbe0acb 100644 --- a/dlls/kernel32/tests/sync.c +++ b/dlls/kernel32/tests/sync.c @@ -24,6 +24,7 @@ #include <stdio.h> #include <windef.h> #include <winbase.h> +#include <winternl.h>
#include "wine/test.h"
@@ -55,6 +56,7 @@ static VOID (WINAPI *pReleaseSRWLockExclusive)(PSRWLOCK); static VOID (WINAPI *pReleaseSRWLockShared)(PSRWLOCK); static BOOLEAN (WINAPI *pTryAcquireSRWLockExclusive)(PSRWLOCK); static BOOLEAN (WINAPI *pTryAcquireSRWLockShared)(PSRWLOCK); +static NTSTATUS (WINAPI *pNtWaitForMultipleObjects)(ULONG,const HANDLE*,BOOLEAN,BOOLEAN,const LARGE_INTEGER*);
static void test_signalandwait(void) { @@ -1153,15 +1155,32 @@ static void test_WaitForMultipleObjects(void) }
/* a manual-reset event remains signaled, an auto-reset event is cleared */ - r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, 0, 0); + r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, FALSE, 0); ok( r == WAIT_OBJECT_0, "should signal lowest handle first, got %d\n", r); - r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, 0, 0); + r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, FALSE, 0); ok( r == WAIT_OBJECT_0, "should signal handle #0 first, got %d\n", r); ok(ResetEvent(maxevents[0]), "ResetEvent\n"); for (i=1; i<MAXIMUM_WAIT_OBJECTS; i++) { /* the lowest index is checked first and remaining events are untouched */ - r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, 0, 0); + r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, FALSE, 0); + ok( r == WAIT_OBJECT_0+i, "should signal handle #%d first, got %d\n", i, r); + } + + /* run same test with Nt* call */ + for (i=0; i<MAXIMUM_WAIT_OBJECTS; i++) + SetEvent(maxevents[i]); + + /* a manual-reset event remains signaled, an auto-reset event is cleared */ + r = pNtWaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, TRUE, FALSE, NULL); + ok( r == WAIT_OBJECT_0, "should signal lowest handle first, got %d\n", r); + r = pNtWaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, TRUE, FALSE, NULL); + ok( r == WAIT_OBJECT_0, "should signal handle #0 first, got %d\n", r); + ok(ResetEvent(maxevents[0]), "ResetEvent\n"); + for (i=1; i<MAXIMUM_WAIT_OBJECTS; i++) + { + /* the lowest index is checked first and remaining events are untouched */ + r = pNtWaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, TRUE, FALSE, NULL); ok( r == WAIT_OBJECT_0+i, "should signal handle #%d first, got %d\n", i, r); }
@@ -2287,6 +2306,8 @@ static void test_srwlock_example(void) START_TEST(sync) { HMODULE hdll = GetModuleHandleA("kernel32.dll"); + HMODULE hntdll = GetModuleHandleA("ntdll.dll"); + pChangeTimerQueueTimer = (void*)GetProcAddress(hdll, "ChangeTimerQueueTimer"); pCreateTimerQueue = (void*)GetProcAddress(hdll, "CreateTimerQueue"); pCreateTimerQueueTimer = (void*)GetProcAddress(hdll, "CreateTimerQueueTimer"); @@ -2312,6 +2333,7 @@ START_TEST(sync) pReleaseSRWLockShared = (void *)GetProcAddress(hdll, "ReleaseSRWLockShared"); pTryAcquireSRWLockExclusive = (void *)GetProcAddress(hdll, "TryAcquireSRWLockExclusive"); pTryAcquireSRWLockShared = (void *)GetProcAddress(hdll, "TryAcquireSRWLockShared"); + pNtWaitForMultipleObjects = (void *)GetProcAddress(hntdll, "NtWaitForMultipleObjects");
test_signalandwait(); test_mutex(); diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c index 7c9d5e8..08fab44 100644 --- a/dlls/ntdll/sync.c +++ b/dlls/ntdll/sync.c @@ -849,7 +849,7 @@ NTSTATUS WINAPI NtSetTimerResolution(IN ULONG resolution, * NtWaitForMultipleObjects (NTDLL.@) */ NTSTATUS WINAPI NtWaitForMultipleObjects( DWORD count, const HANDLE *handles, - BOOLEAN wait_all, BOOLEAN alertable, + BOOLEAN wait_any, BOOLEAN alertable, const LARGE_INTEGER *timeout ) { select_op_t select_op; @@ -858,7 +858,7 @@ NTSTATUS WINAPI NtWaitForMultipleObjects( DWORD count, const HANDLE *handles, if (!count || count > MAXIMUM_WAIT_OBJECTS) return STATUS_INVALID_PARAMETER_1;
if (alertable) flags |= SELECT_ALERTABLE; - select_op.wait.op = wait_all ? SELECT_WAIT_ALL : SELECT_WAIT; + select_op.wait.op = wait_any ? SELECT_WAIT : SELECT_WAIT_ALL; for (i = 0; i < count; i++) select_op.wait.handles[i] = wine_server_obj_handle( handles[i] ); return server_select( &select_op, offsetof( select_op_t, wait.handles[count] ), flags, timeout ); } diff --git a/dlls/ntdll/threadpool.c b/dlls/ntdll/threadpool.c index f66f6ab..fef26fe 100644 --- a/dlls/ntdll/threadpool.c +++ b/dlls/ntdll/threadpool.c @@ -322,7 +322,7 @@ static DWORD CALLBACK wait_thread_proc(LPVOID Arg)
while (TRUE) { - status = NtWaitForMultipleObjects( 2, handles, FALSE, alertable, + status = NtWaitForMultipleObjects( 2, handles, TRUE, alertable, get_nt_timeout( &timeout, wait_work_item->Milliseconds ) ); if (status == STATUS_WAIT_0 || status == STATUS_TIMEOUT) {