Implemented Nt/KeWaitForMultipleObjects (still buggy).

svn path=/trunk/; revision=651
This commit is contained in:
Eric Kohl 1999-09-08 23:51:36 +00:00
parent 09d88da5e9
commit 1fc6701c79

View file

@ -74,6 +74,8 @@ static BOOLEAN KeDispatcherObjectWakeAll(DISPATCHER_HEADER* hdr)
PKWAIT_BLOCK current;
PLIST_ENTRY current_entry;
DPRINT("KeDispatcherObjectWakeAll(hdr %x)\n",hdr);
if (IsListEmpty(&hdr->WaitListHead))
{
return(FALSE);
@ -85,6 +87,12 @@ static BOOLEAN KeDispatcherObjectWakeAll(DISPATCHER_HEADER* hdr)
current = CONTAINING_RECORD(current_entry,KWAIT_BLOCK,
WaitListEntry);
DPRINT("Waking %x\n",current->Thread);
if (current->NextWaitBlock != NULL)
{
DbgPrint("DANGLING POINTERS!!! We're in trouble!\n");
}
PsResumeThread(CONTAINING_RECORD(current->Thread,ETHREAD,Tcb));
};
return(TRUE);
@ -227,7 +235,7 @@ NTSTATUS KeWaitForSingleObject(PVOID Object,
blk.Object=Object;
blk.Thread=KeGetCurrentThread();
blk.WaitKey = WaitReason; // Assumed
blk.WaitKey = 0;
blk.WaitType = WaitAll;
blk.NextWaitBlock = NULL;
InsertTailList(&(hdr->WaitListHead),&(blk.WaitListEntry));
@ -255,24 +263,43 @@ NTSTATUS KeWaitForMultipleObjects(ULONG Count,
PLARGE_INTEGER Timeout,
PKWAIT_BLOCK WaitBlockArray)
{
#if 0
DISPATCHER_HEADER* hdr;
PKWAIT_BLOCK blk;
ULONG Counter;
ULONG CountSignaled;
ULONG i;
DPRINT("Entering KeWaitForSingleObject(Object %x) "
"PsGetCurrentThread() %x\n",Object,PsGetCurrentThread());
DbgPrint("Entering KeWaitForMultipleObjects(Count %lu Object[] %p) "
"PsGetCurrentThread() %x\n",Count,Object,PsGetCurrentThread());
CountSignaled = 0;
if (WaitBlockArray == NULL)
{
DbgPrint("FIXME: Use internal wait blocks!\n");
return STATUS_UNSUCCESSFUL;
}
else
{
if (Count > 64)
{
DbgPrint("Too many objects!\n");
return STATUS_UNSUCCESSFUL;
}
blk = WaitBlockArray;
}
KeAcquireDispatcherDatabaseLock(FALSE);
for (Counter = 0; Counter < Count; Counter++)
for (i = 0; i < Count; i++)
{
hdr = (DISPATCHER_HEADER *)Object[Counter];
hdr = (DISPATCHER_HEADER *)Object[i];
DPRINT("hdr->SignalState %d\n", hdr->SignalState);
// DbgPrint("hdr->SignalState %d\n", hdr->SignalState);
if (hdr->SignalState > 0)
{
CountSignaled++;
switch (hdr->Type)
{
case SynchronizationEvent:
@ -295,51 +322,67 @@ NTSTATUS KeWaitForMultipleObjects(ULONG Count,
DbgPrint("(%s:%d) Dispatcher object %x has unknown type\n",
__FILE__,__LINE__,hdr);
KeBugCheck(0);
}
if (WaitType == WaitAny)
{
KeReleaseDispatcherDatabaseLock(FALSE);
DbgPrint("One object is already signaled!\n");
return(STATUS_SUCCESS);
}
}
}
if ((WaitType == WaitAll) && (CountSignaled == Count))
{
KeReleaseDispatcherDatabaseLock(FALSE);
DbgPrint("All objects are already signaled!\n");
return(STATUS_SUCCESS);
}
if (Timeout != NULL)
{
KeAddThreadTimeout(KeGetCurrentThread(),Timeout);
}
for (Counter = 0; Counter < Count; Counter++)
for (i = 0; i < Count; i++)
{
hdr = (DISPATCHER_HEADER *)Object[Counter];
hdr = (DISPATCHER_HEADER *)Object[i];
blk = &WaitBlockArray[Counter];
DbgPrint("hdr->SignalState %d\n", hdr->SignalState);
blk->Object=Object[Counter];
blk->Object=Object[i];
blk->Thread=KeGetCurrentThread();
blk->WaitKey = WaitReason; // Assumed
blk->WaitKey = i;
blk->WaitType = WaitType;
if (i == Count - 1)
blk->NextWaitBlock = NULL;
InsertTailList(&(hdr->WaitListHead),&(blk.WaitListEntry));
else
blk->NextWaitBlock = (PVOID)((ULONG)blk+sizeof(KWAIT_BLOCK));
DbgPrint("blk %p blk->NextWaitBlock %p\n",
blk, blk->NextWaitBlock);
InsertTailList(&(hdr->WaitListHead),&(blk->WaitListEntry));
// DPRINT("hdr->WaitListHead.Flink %x hdr->WaitListHead.Blink %x\n",
// hdr->WaitListHead.Flink,hdr->WaitListHead.Blink);
blk = blk->NextWaitBlock;
}
KeReleaseDispatcherDatabaseLock(FALSE);
DPRINT("Waiting at %s:%d with irql %d\n", __FILE__, __LINE__,
DbgPrint("Waiting at %s:%d with irql %d\n", __FILE__, __LINE__,
KeGetCurrentIrql());
PsSuspendThread(PsGetCurrentThread());
if (Timeout != NULL)
{
KeCancelTimer(&KeGetCurrentThread()->Timer);
}
DPRINT("Returning from KeWaitForMultipleObject()\n");
return(STATUS_SUCCESS);
#else
UNIMPLEMENTED;
#endif
DbgPrint("Returning from KeWaitForMultipleObjects()\n");
return STATUS_SUCCESS;
}
VOID KeInitializeDispatcher(VOID)
@ -347,6 +390,7 @@ VOID KeInitializeDispatcher(VOID)
KeInitializeSpinLock(&DispatcherDatabaseLock);
}
NTSTATUS
STDCALL
NtWaitForMultipleObjects (
@ -357,9 +401,10 @@ NtWaitForMultipleObjects (
IN PLARGE_INTEGER Time
)
{
#if 0
KWAIT_BLOCK WaitBlockArray[MAXIMUM_WAIT_OBJECTS];
PVOID ObjectPtrArray[MAXIMUM_WAIT_OBJECTS];
KWAIT_BLOCK WaitBlockArray[64];
PVOID ObjectPtrArray[64];
// KWAIT_BLOCK WaitBlockArray[MAXIMUM_WAIT_OBJECTS];
// PVOID ObjectPtrArray[MAXIMUM_WAIT_OBJECTS];
NTSTATUS Status;
ULONG i, j;
@ -367,8 +412,10 @@ NtWaitForMultipleObjects (
DPRINT("NtWaitForMultipleObjects(Count %lu Object[] %x, Alertable %d, Time %x)\n",
Count,Object,Alertable,Time);
if (Count > MAXIMUM_WAIT_OBJECTS)
return ...; /* WAIT_FAIL */
if (Count > 64)
// if (Count > MAXIMUM_WAIT_OBJECTS)
return STATUS_UNSUCCESSFUL;
// return WAIT_FAIL; /* this must be returned by WaitForMultipleObjects */
/* reference all objects */
for (i = 0; i < Count; i++)
@ -394,7 +441,7 @@ NtWaitForMultipleObjects (
Status = KeWaitForMultipleObjects(Count,
ObjectPtrArray,
WaitType,
UserMode,
UserRequest,
UserMode,
Alertable,
Time,
@ -407,9 +454,6 @@ NtWaitForMultipleObjects (
}
return(Status);
#else
UNIMPLEMENTED;
#endif
}