Author: janderwald
Date: Tue Dec 16 07:19:53 2008
New Revision: 38115
URL:
http://svn.reactos.org/svn/reactos?rev=38115&view=rev
Log:
- Implement KsCreateAllocator, KsRegisterWorker, KsUnregisterWorker,
KsRegisterCountedWorker, KsDecrementCountedWorker, KsIncrementCountedWorker,
KsQueueWorkItem
Modified:
trunk/reactos/drivers/ksfilter/ks/allocators.c
trunk/reactos/drivers/ksfilter/ks/ks.rbuild
trunk/reactos/drivers/ksfilter/ks/worker.c
Modified: trunk/reactos/drivers/ksfilter/ks/allocators.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/alloca…
==============================================================================
--- trunk/reactos/drivers/ksfilter/ks/allocators.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/ksfilter/ks/allocators.c [iso-8859-1] Tue Dec 16 07:19:53 2008
@@ -20,14 +20,13 @@
}
/*
- @unimplemented
+ @implemented
*/
KSDDKAPI NTSTATUS NTAPI
KsCreateDefaultAllocator(
IN PIRP Irp)
{
- UNIMPLEMENTED;
- return STATUS_UNSUCCESSFUL;
+ return KsCreateDefaultAllocatorEx(Irp, NULL, NULL, NULL, NULL, NULL);
}
/*
@@ -54,7 +53,14 @@
IN PFNKSINITIALIZEALLOCATOR InitializeAllocator OPTIONAL,
IN PFNKSDELETEALLOCATOR DeleteAllocator OPTIONAL)
{
- UNIMPLEMENTED;
+ NTSTATUS Status;
+ PKSALLOCATOR_FRAMING AllocatorFraming;
+
+ Status = KsValidateAllocatorCreateRequest(Irp, &AllocatorFraming);
+ if (!NT_SUCCESS(Status))
+ return STATUS_INVALID_PARAMETER;
+
+
return STATUS_UNSUCCESSFUL;
}
Modified: trunk/reactos/drivers/ksfilter/ks/ks.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/ks.rbu…
==============================================================================
--- trunk/reactos/drivers/ksfilter/ks/ks.rbuild [iso-8859-1] (original)
+++ trunk/reactos/drivers/ksfilter/ks/ks.rbuild [iso-8859-1] Tue Dec 16 07:19:53 2008
@@ -6,6 +6,7 @@
<include base="ks">../include</include>
<importlibrary definition="ks.spec" />
<library>ntoskrnl</library>
+ <library>hal</library>
<define name="BUILDING_KS" />
<define name="_NTDDK_" />
<define name="_COMDDK_" />
Modified: trunk/reactos/drivers/ksfilter/ks/worker.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/worker…
==============================================================================
--- trunk/reactos/drivers/ksfilter/ks/worker.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/ksfilter/ks/worker.c [iso-8859-1] Tue Dec 16 07:19:53 2008
@@ -6,30 +6,87 @@
#include <debug.h>
#include <ks.h>
+
+typedef struct
+{
+ KEVENT Event;
+ KSPIN_LOCK Lock;
+ WORK_QUEUE_TYPE Type;
+ LONG Counter;
+ PWORK_QUEUE_ITEM WorkItem;
+ ULONG WorkItemActive;
+ ULONG DeleteInProgress;
+}KS_WORKER;
+
/*
- @unimplemented
+ @implemented
*/
-KSDDKAPI NTSTATUS NTAPI
+KSDDKAPI
+NTSTATUS
+NTAPI
KsRegisterWorker(
IN WORK_QUEUE_TYPE WorkQueueType,
OUT PKSWORKER* Worker)
{
+ KS_WORKER * KsWorker;
UNIMPLEMENTED;
- return STATUS_UNSUCCESSFUL;
+
+ if (WorkQueueType != CriticalWorkQueue &&
+ WorkQueueType != DelayedWorkQueue &&
+ WorkQueueType != HyperCriticalWorkQueue)
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ KsWorker = ExAllocatePoolWithTag(NonPagedPool, sizeof(KS_WORKER), 0);
+ if (!KsWorker)
+ return STATUS_INSUFFICIENT_RESOURCES;
+
+ KsWorker->Type = WorkQueueType;
+ KsWorker->Counter = 0;
+ KsWorker->WorkItemActive = 0;
+ KsWorker->WorkItem = NULL;
+ KsWorker->DeleteInProgress = TRUE;
+ KeInitializeSpinLock(&KsWorker->Lock);
+ KeInitializeEvent(&KsWorker->Event, NotificationEvent, FALSE);
+
+ *Worker = KsWorker;
+ return STATUS_SUCCESS;
}
/*
- @unimplemented
+ @implemented
*/
KSDDKAPI VOID NTAPI
KsUnregisterWorker(
IN PKSWORKER Worker)
{
- UNIMPLEMENTED;
+ KS_WORKER * KsWorker;
+ KIRQL OldIrql;
+ ULONG bWait = FALSE;
+
+ if (!Worker)
+ return;
+
+ KsWorker = (KS_WORKER *)Worker;
+
+ KsWorker->DeleteInProgress = TRUE;
+
+ if (KsWorker->WorkItemActive)
+ {
+ KeReleaseSpinLock(&KsWorker->Lock, OldIrql);
+ KeWaitForSingleObject(&KsWorker->Event, Executive, KernelMode, FALSE,
NULL);
+ }
+ else
+ {
+ KeReleaseSpinLock(&KsWorker->Lock, OldIrql);
+ }
+
+ ExFreePoolWithTag(KsWorker, 0);
}
/*
- @unimplemented
+ @implemented
*/
KSDDKAPI NTSTATUS NTAPI
KsRegisterCountedWorker(
@@ -37,40 +94,98 @@
IN PWORK_QUEUE_ITEM CountedWorkItem,
OUT PKSWORKER* Worker)
{
- UNIMPLEMENTED;
- return STATUS_UNSUCCESSFUL;
+ NTSTATUS Status;
+ KS_WORKER * KsWorker;
+
+ Status = KsRegisterWorker(WorkQueueType, Worker);
+
+ if (NT_SUCCESS(Status))
+ {
+ KsWorker = (KS_WORKER *)Worker;
+ KsWorker->WorkItem = CountedWorkItem;
+ }
+
+ return Status;
}
/*
- @unimplemented
+ @implemented
*/
-KSDDKAPI ULONG NTAPI
+KSDDKAPI
+ULONG
+NTAPI
KsDecrementCountedWorker(
IN PKSWORKER Worker)
{
- UNIMPLEMENTED;
- return 0;
+ KS_WORKER * KsWorker;
+ LONG Counter;
+
+ if (!Worker)
+ return STATUS_INVALID_PARAMETER;
+
+ KsWorker = (KS_WORKER *)Worker;
+ Counter = InterlockedDecrement(&KsWorker->Counter);
+
+ if (KsWorker->DeleteInProgress)
+ {
+ /* signal that we are done */
+ KeSetEvent(&KsWorker->Event, 0, 0);
+ }
+
+ return Counter;
}
/*
- @unimplemented
+ @implemented
*/
-KSDDKAPI ULONG NTAPI
+KSDDKAPI
+ULONG
+NTAPI
KsIncrementCountedWorker(
IN PKSWORKER Worker)
{
- UNIMPLEMENTED;
- return 0;
+ KS_WORKER * KsWorker;
+ LONG Counter;
+
+ if (!Worker)
+ return STATUS_INVALID_PARAMETER;
+
+ KsWorker = (KS_WORKER *)Worker;
+
+ Counter = InterlockedIncrement(&KsWorker->Counter);
+ if (Counter == 1)
+ {
+ KsQueueWorkItem(Worker, KsWorker->WorkItem);
+ }
+ return Counter;
}
/*
- @unimplemented
+ @implemented
*/
-KSDDKAPI NTSTATUS NTAPI
+KSDDKAPI
+NTSTATUS
+NTAPI
KsQueueWorkItem(
IN PKSWORKER Worker,
IN PWORK_QUEUE_ITEM WorkItem)
{
- UNIMPLEMENTED;
- return STATUS_UNSUCCESSFUL;
+ KS_WORKER * KsWorker;
+ KIRQL OldIrql;
+ NTSTATUS Status = STATUS_SUCCESS;
+
+ if (!Worker || !WorkItem)
+ return STATUS_INVALID_PARAMETER;
+
+ KsWorker = (KS_WORKER *)Worker;
+ KeAcquireSpinLock(&KsWorker->Lock, &OldIrql);
+
+ if (!KsWorker->DeleteInProgress)
+ {
+ ExQueueWorkItem(WorkItem, KsWorker->Type);
+ Status = STATUS_UNSUCCESSFUL;
+ }
+
+ KeReleaseSpinLock(&KsWorker->Lock, OldIrql);
+ return Status;
}