started moving tags to a private internal header
[reactos.git] / reactos / ntoskrnl / io / iowork.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/iowork.c
6 * PURPOSE: Manage IO system work queues
7 *
8 * PROGRAMMERS: David Welch (welch@mcmail.com)
9 * Robert Dickenson (odin@pnc.com.au)
10 */
11
12 /* INCLUDES ******************************************************************/
13
14 #include <ntoskrnl.h>
15 #define NDEBUG
16 #include <internal/debug.h>
17
18 /* TYPES ********************************************************************/
19
20 typedef struct _IO_WORKITEM
21 {
22 WORK_QUEUE_ITEM Item;
23 PDEVICE_OBJECT DeviceObject;
24 PIO_WORKITEM_ROUTINE WorkerRoutine;
25 PVOID Context;
26 } IO_WORKITEM;
27
28 /* FUNCTIONS ****************************************************************/
29
30 VOID STATIC STDCALL
31 IoWorkItemCallback(PVOID Parameter)
32 {
33 PIO_WORKITEM IoWorkItem = (PIO_WORKITEM)Parameter;
34 PDEVICE_OBJECT DeviceObject = IoWorkItem->DeviceObject;
35 IoWorkItem->WorkerRoutine(IoWorkItem->DeviceObject, IoWorkItem->Context);
36 ObDereferenceObject(DeviceObject);
37 }
38
39 /*
40 * @implemented
41 */
42 VOID STDCALL
43 IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem,
44 IN PIO_WORKITEM_ROUTINE WorkerRoutine,
45 IN WORK_QUEUE_TYPE QueueType,
46 IN PVOID Context)
47 /*
48 * FUNCTION: Inserts a work item in a queue for one of the system worker
49 * threads to process
50 * ARGUMENTS:
51 * IoWorkItem = Item to insert
52 * QueueType = Queue to insert it in
53 */
54 {
55 ExInitializeWorkItem(&IoWorkItem->Item, IoWorkItemCallback,
56 (PVOID)IoWorkItem);
57 IoWorkItem->WorkerRoutine = WorkerRoutine;
58 IoWorkItem->Context = Context;
59 ObReferenceObjectByPointer(IoWorkItem->DeviceObject,
60 FILE_ALL_ACCESS,
61 NULL,
62 KernelMode);
63 ExQueueWorkItem(&IoWorkItem->Item, QueueType);
64 }
65
66 /*
67 * @implemented
68 */
69 VOID STDCALL
70 IoFreeWorkItem(PIO_WORKITEM IoWorkItem)
71 {
72 ExFreePool(IoWorkItem);
73 }
74
75 /*
76 * @implemented
77 */
78 PIO_WORKITEM STDCALL
79 IoAllocateWorkItem(PDEVICE_OBJECT DeviceObject)
80 {
81 PIO_WORKITEM IoWorkItem = NULL;
82
83 IoWorkItem =
84 ExAllocatePoolWithTag(NonPagedPool, sizeof(IO_WORKITEM), TAG_IOWI);
85 if (IoWorkItem == NULL)
86 {
87 return(NULL);
88 }
89 RtlZeroMemory(IoWorkItem, sizeof(IO_WORKITEM));
90 IoWorkItem->DeviceObject = DeviceObject;
91 return(IoWorkItem);
92 }
93
94 /* EOF */