2 * PROJECT: ReactOS TDI driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/network/tdi/cte/events.c
5 * PURPOSE: CTE events support
6 * PROGRAMMERS: Oleg Baikalow (obaikalow@gmail.com)
9 /* INCLUDES *****************************************************************/
13 typedef struct _CTEBLOCK_EVENT
17 } CTEBLOCK_EVENT
, *PCTEBLOCK_EVENT
;
19 struct _CTE_DELAYED_EVENT
;
20 typedef void (*CTE_WORKER_ROUTINE
)(struct _CTE_DELAYED_EVENT
*, void *Context
);
22 typedef struct _CTE_DELAYED_EVENT
26 CTE_WORKER_ROUTINE WorkerRoutine
;
28 WORK_QUEUE_ITEM WorkItem
;
29 } CTE_DELAYED_EVENT
, *PCTE_DELAYED_EVENT
;
31 /* FUNCTIONS *****************************************************************/
38 CTEBlock(PCTEBLOCK_EVENT Block
)
42 /* Perform the wait */
43 Status
= KeWaitForSingleObject(&Block
->Event
, UserRequest
, KernelMode
, FALSE
, NULL
);
45 /* Update event status if wait was not successful */
46 if (!NT_SUCCESS(Status
)) Block
->Status
= Status
;
54 InternalWorker(IN PVOID Parameter
)
56 PCTE_DELAYED_EVENT Event
= (PCTE_DELAYED_EVENT
)Parameter
;
59 /* Acquire the lock */
60 KeAcquireSpinLock(&Event
->Lock
, &OldIrql
);
62 /* Make sure it is queued */
63 ASSERT(Event
->Queued
);
64 Event
->Queued
= FALSE
;
66 /* Release the lock */
67 KeReleaseSpinLock(&Event
->Lock
, OldIrql
);
69 /* Call the real worker routine */
70 (*Event
->WorkerRoutine
)(Event
, Event
->Context
);
79 CTEInitEvent(PCTE_DELAYED_EVENT Event
,
80 CTE_WORKER_ROUTINE Routine
)
82 /* Init the structure, lock and a work item */
83 Event
->Queued
= FALSE
;
84 KeInitializeSpinLock(&Event
->Lock
);
85 Event
->WorkerRoutine
= Routine
;
86 ExInitializeWorkItem(&Event
->WorkItem
, InternalWorker
, Event
);
105 * IoAllocateErrorLogEntry and
106 * IoWriteErrorLogEntry
108 return STATUS_NOT_IMPLEMENTED
;
117 CTEScheduleEvent(PCTE_DELAYED_EVENT Event
,
122 /* Acquire the lock */
123 KeAcquireSpinLock(&Event
->Lock
, &OldIrql
);
125 /* Make sure it is queued */
128 /* Mark it as queued and set optional context pointer */
129 Event
->Queued
= TRUE
;
130 Event
->Context
= Context
;
132 /* Actually queue it */
133 ExQueueWorkItem(&Event
->WorkItem
, CriticalWorkQueue
);
136 /* Release the lock */
137 KeReleaseSpinLock(&Event
->Lock
, OldIrql
);
148 CTESignal(PCTEBLOCK_EVENT Block
, NTSTATUS Status
)
150 /* Set status right away */
151 Block
->Status
= Status
;
154 return KeSetEvent(&Block
->Event
, IO_NO_INCREMENT
, FALSE
);