xref: /reactos/ntoskrnl/io/iomgr/iowork.c (revision c2c66aff)
1 /*
2  * PROJECT:         ReactOS Kernel
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            ntoskrnl/io/iomgr/iowork.c
5  * PURPOSE:         I/O Wrappers for the Executive Work Item Functions
6  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
7  *                  Robert Dickenson (odin@pnc.com.au)
8  */
9 
10 /* INCLUDES ******************************************************************/
11 
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* PRIVATE FUNCTIONS *********************************************************/
17 
18 VOID
19 NTAPI
IopWorkItemCallback(IN PVOID Parameter)20 IopWorkItemCallback(IN PVOID Parameter)
21 {
22     PIO_WORKITEM IoWorkItem = (PIO_WORKITEM)Parameter;
23     PDEVICE_OBJECT DeviceObject = IoWorkItem->DeviceObject;
24     PAGED_CODE();
25 
26     /* Call the work routine */
27     IoWorkItem->WorkerRoutine(DeviceObject, IoWorkItem->Context);
28 
29     /* Dereference the device object */
30     ObDereferenceObject(DeviceObject);
31 }
32 
33 /* PUBLIC FUNCTIONS **********************************************************/
34 
35 /*
36  * @implemented
37  */
38 VOID
39 NTAPI
IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem,IN PIO_WORKITEM_ROUTINE WorkerRoutine,IN WORK_QUEUE_TYPE QueueType,IN PVOID Context)40 IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem,
41                 IN PIO_WORKITEM_ROUTINE WorkerRoutine,
42                 IN WORK_QUEUE_TYPE QueueType,
43                 IN PVOID Context)
44 {
45     /* Make sure we're called at DISPATCH or lower */
46     ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
47 
48     /* Reference the device object */
49     ObReferenceObject(IoWorkItem->DeviceObject);
50 
51     /* Setup the work item */
52     IoWorkItem->WorkerRoutine = WorkerRoutine;
53     IoWorkItem->Context = Context;
54 
55     /* Queue the work item */
56     ExQueueWorkItem(&IoWorkItem->Item, QueueType);
57 }
58 
59 /*
60  * @implemented
61  */
62 VOID
63 NTAPI
IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)64 IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
65 {
66     /* Free the work item */
67     ExFreePool(IoWorkItem);
68 }
69 
70 /*
71  * @implemented
72  */
73 PIO_WORKITEM
74 NTAPI
IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)75 IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
76 {
77     PIO_WORKITEM IoWorkItem;
78 
79     /* Allocate the work item */
80     IoWorkItem = ExAllocatePoolWithTag(NonPagedPool,
81                                        sizeof(IO_WORKITEM),
82                                        TAG_IOWI);
83     if (!IoWorkItem) return NULL;
84 
85     /* Initialize it */
86     IoWorkItem->DeviceObject = DeviceObject;
87     ExInitializeWorkItem(&IoWorkItem->Item, IopWorkItemCallback, IoWorkItem);
88 
89     /* Return it */
90     return IoWorkItem;
91 }
92 
93 /* EOF */
94