Author: fireball
Date: Sat Jan 29 11:13:51 2011
New Revision: 50550
URL:
http://svn.reactos.org/svn/reactos?rev=50550&view=rev
Log:
[TDI]
- Oleg Baikalow: Implement basic event and delayed event support functions for CTE.
Structure names are made up, but their contents should be compatible with what Windows
2003 tdi.sys uses. Formatting and coding style fixes by the committer.
Modified:
trunk/reactos/drivers/network/tdi/cte/stubs.c
Modified: trunk/reactos/drivers/network/tdi/cte/stubs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tdi/cte/st…
==============================================================================
--- trunk/reactos/drivers/network/tdi/cte/stubs.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tdi/cte/stubs.c [iso-8859-1] Sat Jan 29 11:13:51 2011
@@ -1,32 +1,91 @@
-/* $Id$
- *
- */
+/*
+ * PROJECT: ReactOS TDI driver
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: drivers/network/tdi/stubs.c
+ * PURPOSE: TDI misc support routines
+ * PROGRAMMERS: Oleg Baikalow (obaikalow(a)gmail.com)
+ */
+
+/* INCLUDES *****************************************************************/
+
#include <ntddk.h>
-/*
- * @unimplemented
+typedef struct _CTEBLOCK_EVENT
+{
+ NTSTATUS Status;
+ KEVENT Event;
+} CTEBLOCK_EVENT, *PCTEBLOCK_EVENT;
+
+struct _CTE_DELAYED_EVENT;
+typedef void (*CTE_WORKER_ROUTINE)(struct _CTE_DELAYED_EVENT *, void *Context);
+
+typedef struct _CTE_DELAYED_EVENT
+{
+ BOOLEAN Queued;
+ KSPIN_LOCK Lock;
+ CTE_WORKER_ROUTINE WorkerRoutine;
+ PVOID Context;
+ WORK_QUEUE_ITEM WorkItem;
+} CTE_DELAYED_EVENT, *PCTE_DELAYED_EVENT;
+
+
+/* FUNCTIONS *****************************************************************/
+
+/*
+ * @implemented
*/
NTSTATUS
NTAPI
-CTEBlock (
- ULONG Unknown0
- )
-{
- return STATUS_NOT_IMPLEMENTED;
-}
-
-
-/*
- * @unimplemented
- */
+CTEBlock(PCTEBLOCK_EVENT Block)
+{
+ NTSTATUS Status;
+
+ /* Perform the wait */
+ Status = KeWaitForSingleObject(&Block->Event, UserRequest, KernelMode, FALSE,
NULL);
+
+ /* Update event status if wait was not successful */
+ if (!NT_SUCCESS(Status)) Block->Status = Status;
+
+ return Block->Status;
+}
+
+
VOID
NTAPI
-CTEInitEvent (
- ULONG Unknown0,
- ULONG Unknown1
- )
-{
+InternalWorker(IN PVOID Parameter)
+{
+ PCTE_DELAYED_EVENT Event = (PCTE_DELAYED_EVENT)Parameter;
+ KIRQL OldIrql;
+
+ /* Acquire the lock */
+ KeAcquireSpinLock(&Event->Lock, &OldIrql);
+
+ /* Make sure it is queued */
+ ASSERT(Event->Queued);
+ Event->Queued = FALSE;
+
+ /* Release the lock */
+ KeReleaseSpinLock(&Event->Lock, OldIrql);
+
+ /* Call the real worker routine */
+ (*Event->WorkerRoutine)(Event, Event->Context);
+}
+
+
+/*
+ * @implemented
+ */
+VOID
+NTAPI
+CTEInitEvent(PCTE_DELAYED_EVENT Event,
+ CTE_WORKER_ROUTINE Routine)
+{
+ /* Init the structure, lock and a work item */
+ Event->Queued = FALSE;
+ KeInitializeSpinLock(&Event->Lock);
+ Event->WorkerRoutine = Routine;
+ ExInitializeWorkItem(&Event->WorkItem, InternalWorker, Event);
}
@@ -80,39 +139,48 @@
/*
- * @unimplemented
+ * @implemented
*/
BOOLEAN
NTAPI
-CTEScheduleEvent (
- ULONG Unknown0,
- ULONG Unknown1
- )
-{
- return FALSE;
-}
-
-
-/*
- * @unimplemented
+CTEScheduleEvent(PCTE_DELAYED_EVENT Event,
+ PVOID Context)
+{
+ KIRQL OldIrql;
+
+ /* Acquire the lock */
+ KeAcquireSpinLock(&Event->Lock, &OldIrql);
+
+ /* Make sure it is queued */
+ if (!Event->Queued);
+ {
+ /* Mark it as queued and set optional context pointer */
+ Event->Queued = TRUE;
+ Event->Context = Context;
+
+ /* Actually queue it */
+ ExQueueWorkItem(&Event->WorkItem, CriticalWorkQueue);
+ }
+
+ /* Release the lock */
+ KeReleaseSpinLock(&Event->Lock, OldIrql);
+
+ return TRUE;
+}
+
+
+/*
+ * @implemented
*/
LONG
NTAPI
-CTESignal (
- ULONG Unknown0,
- ULONG Unknown1
- )
-{
-#if 0
- PKEVENT kevent = (PKEVENT) Unknown0;
-
- return KeSetEvent (
- kevent,
- 0,
- FALSE
- );
-#endif
- return 0;
+CTESignal(PCTEBLOCK_EVENT Block, NTSTATUS Status)
+{
+ /* Set status right away */
+ Block->Status = Status;
+
+ /* Set the event */
+ return KeSetEvent(&Block->Event, IO_NO_INCREMENT, FALSE);
}