1 /*++ 2 3 Copyright (c) Microsoft Corporation 4 5 ModuleName: 6 7 MxWorkItemKm.h 8 9 Abstract: 10 11 Kernel mode implementation of work item 12 class defined in MxWorkItem.h 13 14 Author: 15 16 17 18 Revision History: 19 20 21 22 --*/ 23 24 #pragma once 25 26 typedef IO_WORKITEM_ROUTINE MX_WORKITEM_ROUTINE, *PMX_WORKITEM_ROUTINE; 27 typedef PIO_WORKITEM MdWorkItem; 28 29 #include "mxworkitem.h" 30 31 __inline 32 MxWorkItem::MxWorkItem( 33 ) 34 { 35 m_WorkItem = NULL; 36 } 37 38 _Must_inspect_result_ 39 __inline 40 NTSTATUS 41 MxWorkItem::Allocate( 42 __in MdDeviceObject DeviceObject, 43 __in_opt PVOID ThreadPoolEnv 44 ) 45 { 46 UNREFERENCED_PARAMETER(ThreadPoolEnv); 47 48 m_WorkItem = IoAllocateWorkItem(DeviceObject); 49 if (NULL == m_WorkItem) { 50 return STATUS_INSUFFICIENT_RESOURCES; 51 } 52 53 return STATUS_SUCCESS; 54 } 55 56 __inline 57 VOID 58 MxWorkItem::Enqueue( 59 __in PMX_WORKITEM_ROUTINE Callback, 60 __in PVOID Context 61 ) 62 { 63 IoQueueWorkItem( 64 m_WorkItem, 65 Callback, 66 DelayedWorkQueue, 67 Context 68 ); 69 } 70 71 __inline 72 MdWorkItem 73 MxWorkItem::GetWorkItem( 74 ) 75 { 76 return m_WorkItem; 77 } 78 79 __inline 80 VOID 81 MxWorkItem::_Free( 82 __in MdWorkItem Item 83 ) 84 { 85 IoFreeWorkItem(Item); 86 } 87 88 __inline 89 VOID 90 MxWorkItem::Free( 91 ) 92 { 93 if (NULL != m_WorkItem) { 94 MxWorkItem::_Free(m_WorkItem); 95 m_WorkItem = NULL; 96 } 97 } 98 99 // 100 // FxAutoWorkitem 101 // 102 __inline 103 MxAutoWorkItem::~MxAutoWorkItem( 104 ) 105 { 106 this->Free(); 107 } 108 109 110