1 /*++
2 
3 Copyright (c) Microsoft. All rights reserved.
4 
5 Module Name:
6 
7     EventQueueUm.cpp
8 
9 Abstract:
10 
11     This module implements user mode specific functionality of event queue
12 
13     This functionality needed to be separated out since the KM portion takes
14     a reference on driver object because KM MxWorkItem::_Free does not wait for
15     callback to return (i.e. rundown synchronously).
16 
17     MxWorkItem::_Free in UM currently waits for callback to return (i.e. runs
18     down synchronously) hence does not need a reference on driver/devstack
19     object (see comments on top of MxWorkItemUm.h file).
20 
21     In future if UM work-item is made similar to km workitem, UMDF may need to
22     ensure that modules stay loaded, though the mechanism to ensure that would
23     likely be different from a reference on the driver. It would likely be a
24     reference on the devicestack object.
25 
26 Environment:
27 
28     User mode only
29 
30 Revision History:
31 
32 
33 
34 
35 --*/
36 
37 #include "pnppriv.hpp"
38 
39 VOID
40 FxWorkItemEventQueue::QueueWorkItem(
41     VOID
42     )
43 {
44     //
45     // In user mode WorkItem::_Free waits for workitem callbacks to return
46     // So we don't need outstanding reference on driver object or the devstack
47     //
48 
49     m_WorkItem.Enqueue(
50         (PMX_WORKITEM_ROUTINE) _WorkItemCallback,
51         (FxEventQueue*) this);
52 }
53 
54 VOID
55 FxWorkItemEventQueue::_WorkItemCallback(
56     __in MdDeviceObject DeviceObject,
57     __in PVOID Context
58     )
59 /*++
60 
61 Routine Description:
62     This is the work item that attempts to run the machine on a thread
63     separate from the one the caller was using.  It implements step 9 above.
64 
65 --*/
66 {
67     FxWorkItemEventQueue* This = (FxWorkItemEventQueue*) Context;
68 
69     UNREFERENCED_PARAMETER(DeviceObject);
70 
71     //
72     // In user mode WorkItem::_Free waits for workitem callbacks to return
73     // So we don't need outstanding reference on driver object
74     //
75 
76     This->EventQueueWorker();
77 }
78