From 58f7f41275ec29bb8079163e696ae555232870b4 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 2 Jan 2001 00:47:08 +0000 Subject: [PATCH] Implemented NtSignalAndWaitForSingleObject() svn path=/trunk/; revision=1491 --- reactos/include/ddk/zw.h | 73 +++++++++++++++++++---------------- reactos/ntoskrnl/ke/wait.c | 79 +++++++++++++++++++++++++++++++++++--- 2 files changed, 112 insertions(+), 40 deletions(-) diff --git a/reactos/include/ddk/zw.h b/reactos/include/ddk/zw.h index 9338968264c..e01774d3749 100644 --- a/reactos/include/ddk/zw.h +++ b/reactos/include/ddk/zw.h @@ -1,5 +1,5 @@ -/* $Id: zw.h,v 1.39 2000/12/23 02:37:36 dwelch Exp $ +/* $Id: zw.h,v 1.40 2001/01/02 00:46:10 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -4844,44 +4844,43 @@ ZwUnmapViewOfSection( /* --- OBJECT SYNCHRONIZATION --- */ /* - * FUNCTION: Signals an event and wait for it to be signaled again. + * FUNCTION: Signals an object and wait for an other one. * ARGUMENTS: - * EventHandle = Handle to the event that should be signaled - * Alertable = True if the wait is alertable + * SignalObject = Handle to the object that should be signaled + * WaitObject = Handle to the object that should be waited for + * Alertable = True if the wait is alertable * Time = The time to wait - * NumberOfWaitingThreads = Number of waiting threads * RETURNS: Status - */ - -NTSTATUS -STDCALL + */ +NTSTATUS +STDCALL NtSignalAndWaitForSingleObject( - IN HANDLE EventHandle, - IN BOOLEAN Alertable, - IN PLARGE_INTEGER Time, - PULONG NumberOfWaitingThreads OPTIONAL + IN HANDLE SignalObject, + IN HANDLE WaitObject, + IN BOOLEAN Alertable, + IN PLARGE_INTEGER Time ); -NTSTATUS -STDCALL -ZwSignalAndWaitForSingleObject( - IN HANDLE EventHandle, - IN BOOLEAN Alertable, - IN PLARGE_INTEGER Time, - PULONG NumberOfWaitingThreads OPTIONAL +NTSTATUS +STDCALL +NtSignalAndWaitForSingleObject( + IN HANDLE SignalObject, + IN HANDLE WaitObject, + IN BOOLEAN Alertable, + IN PLARGE_INTEGER Time ); /* - * FUNCTION: Waits for multiple objects to become signalled. + * FUNCTION: Waits for multiple objects to become signalled. * ARGUMENTS: * Count = The number of objects * Object = The array of object handles * WaitType = Can be one of the values UserMode or KernelMode * Alertable = If true the wait is alertable. - * Time = The maximum wait time. + * Time = The maximum wait time. * REMARKS: - * This function maps to the win32 WaitForMultipleObjectEx. - * RETURNS: Status + * This function maps to the win32 WaitForMultipleObjectEx. + * RETURNS: Status */ NTSTATUS STDCALL @@ -4890,7 +4889,7 @@ NtWaitForMultipleObjects ( IN HANDLE Object[], IN CINT WaitType, IN BOOLEAN Alertable, - IN PLARGE_INTEGER Time + IN PLARGE_INTEGER Time ); NTSTATUS @@ -4900,24 +4899,25 @@ ZwWaitForMultipleObjects ( IN HANDLE Object[], IN CINT WaitType, IN BOOLEAN Alertable, - IN PLARGE_INTEGER Time + IN PLARGE_INTEGER Time ); + /* - * FUNCTION: Waits for an object to become signalled. + * FUNCTION: Waits for an object to become signalled. * ARGUMENTS: * Object = The object handle * Alertable = If true the wait is alertable. * Time = The maximum wait time. * REMARKS: - * This function maps to the win32 WaitForSingleObjectEx. - * RETURNS: Status + * This function maps to the win32 WaitForSingleObjectEx. + * RETURNS: Status */ NTSTATUS STDCALL NtWaitForSingleObject ( IN HANDLE Object, IN BOOLEAN Alertable, - IN PLARGE_INTEGER Time + IN PLARGE_INTEGER Time ); NTSTATUS @@ -4925,16 +4925,16 @@ STDCALL ZwWaitForSingleObject ( IN HANDLE Object, IN BOOLEAN Alertable, - IN PLARGE_INTEGER Time + IN PLARGE_INTEGER Time ); /* --- EVENT PAIR OBJECT --- */ /* * FUNCTION: Waits for the high part of an eventpair to become signalled - * ARGUMENTS: + * ARGUMENTS: * EventPairHandle = Handle to the event pair. - * RETURNS: Status + * RETURNS: Status */ NTSTATUS @@ -4949,7 +4949,12 @@ ZwWaitHighEventPair( IN HANDLE EventPairHandle ); - +/* + * FUNCTION: Waits for the low part of an eventpair to become signalled + * ARGUMENTS: + * EventPairHandle = Handle to the event pair. + * RETURNS: Status + */ NTSTATUS STDCALL NtWaitLowEventPair( diff --git a/reactos/ntoskrnl/ke/wait.c b/reactos/ntoskrnl/ke/wait.c index ec09986892c..bfb27680ee0 100644 --- a/reactos/ntoskrnl/ke/wait.c +++ b/reactos/ntoskrnl/ke/wait.c @@ -677,11 +677,78 @@ NTSTATUS STDCALL NtWaitForSingleObject (IN HANDLE Object, } -NTSTATUS STDCALL NtSignalAndWaitForSingleObject (IN HANDLE EventHandle, - IN BOOLEAN Alertable, - IN PLARGE_INTEGER Time, - PULONG - NumberOfWaitingThreads OPTIONAL) +NTSTATUS STDCALL +NtSignalAndWaitForSingleObject(IN HANDLE SignalObject, + IN HANDLE WaitObject, + IN BOOLEAN Alertable, + IN PLARGE_INTEGER Time) { - UNIMPLEMENTED; + KPROCESSOR_MODE ProcessorMode; + DISPATCHER_HEADER* hdr; + PVOID SignalObj; + PVOID WaitObj; + NTSTATUS Status; + + ProcessorMode = CURRENT_KPCR->CurrentThread->PreviousMode; + Status = ObReferenceObjectByHandle(SignalObject, + 0, + NULL, + ProcessorMode, + &SignalObj, + NULL); + if (!NT_SUCCESS(Status)) + { + return Status; + } + + Status = ObReferenceObjectByHandle(WaitObject, + SYNCHRONIZE, + NULL, + ProcessorMode, + &WaitObj, + NULL); + if (!NT_SUCCESS(Status)) + { + ObDereferenceObject(SignalObj); + return Status; + } + + hdr = (DISPATCHER_HEADER *)SignalObj; + switch (hdr->Type) + { + case InternalNotificationEvent: + case InternalSynchronizationEvent: + KeSetEvent(SignalObj, + EVENT_INCREMENT, + TRUE); + break; + + case InternalMutexType: + KeReleaseMutex(SignalObj, + TRUE); + break; + + case InternalSemaphoreType: + KeReleaseSemaphore(SignalObj, + SEMAPHORE_INCREMENT, + 1, + TRUE); + break; + + default: + ObDereferenceObject(SignalObj); + ObDereferenceObject(WaitObj); + return STATUS_OBJECT_TYPE_MISMATCH; + } + + Status = KeWaitForSingleObject(WaitObj, + UserRequest, + ProcessorMode, + Alertable, + Time); + + ObDereferenceObject(SignalObj); + ObDereferenceObject(WaitObj); + + return Status; }