From 5d61a4a79a1e96dc5d9af1e5e712c84507307544 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Wed, 29 Jul 2015 15:40:09 -0700 Subject: Samples update for public Windows 10 release Fix #2 Enabling WPP Recorder in Sensors Samples causes errors Fix #4 Add back fixed KMDOD sample Add new BarcodeScanner sample in pos folder Add new MagneticStripeReader sample in pos folder Add new SynpaticsTouch sample in input folder Add new Power Engine Plugin sample in pofx folder Add new DeviceMft sample in avstream folder Add new AvsCamera sample in root Add new SimBatt sample in root Add other pre-existing samples not yet released for Win10 --- avscamera/sys/WorkItem.cpp | 167 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 avscamera/sys/WorkItem.cpp (limited to 'avscamera/sys/WorkItem.cpp') diff --git a/avscamera/sys/WorkItem.cpp b/avscamera/sys/WorkItem.cpp new file mode 100644 index 00000000..9bb0d795 --- /dev/null +++ b/avscamera/sys/WorkItem.cpp @@ -0,0 +1,167 @@ +/************************************************************************** + + A/V Stream Camera Sample + + Copyright (c) 2014, Microsoft Corporation. + + File: + + workitem.cpp + + Abstract: + + This module contains an implementation for KWorkItem. + + A KWorkItem inherits from CRef and is reference counted. The object + cannot be destroyed until all references are released. This includes + the reference held when the workitem is in flight. This allows you + to store the workitem in an object that has a lifecycle shorter than + the parent device object. + + History: + + created 5/30/2014 + +**************************************************************************/ + +#include "Common.h" + +KWorkItem:: +KWorkItem( + _In_ PDEVICE_OBJECT DeviceObj, + _In_ PIO_WORKITEM_ROUTINE Callback, + _In_ PVOID Context, + _In_ WORK_QUEUE_TYPE QueueType +) + : m_Callback( Callback ) + , m_Context ( Context ) + , m_QueueType( QueueType ) +/*++ + +Routine Description: + + Constructor. + + Sets up callback handler for the workitem and performs initialization. + +Arguments: + + None. + +Return Value: + + None. + +--*/ +{ + m_WorkItem = IoAllocateWorkItem( DeviceObj ); +} + + +KWorkItem:: +~KWorkItem() +/*++ + +Routine Description: + + Destructor. + + Blocks until all references are released, then frees the workitem. + +Arguments: + + None. + +Return Value: + + None. + +--*/ +{ + // Make sure the work item has been run down. + Wait(); + + // Now delete it. + if( m_WorkItem ) + { + IoFreeWorkItem( m_WorkItem ); + } +} + +BOOLEAN +KWorkItem:: +Start() +/*++ + +Routine Description: + + Enqueue this workitem and acquires a reference on the object. + +Arguments: + + None. + +Return Value: + + TRUE - a workitem was scheduled. + +--*/ +{ + // Make sure construction succeeded. + if( m_WorkItem ) + { + // Make sure the work item isn't already in flight and acquire the lock. + // This is to make sure this KWorkItem doesn't get destroyed until + // the callback is complete. + if( Acquire() ) + { + // Schedule the work item. + IoQueueWorkItem( m_WorkItem, &KWorkItem::Handler, m_QueueType, this ); + + // Note: Release() is called in Handler. + return TRUE; + } + } + return FALSE; +} + +VOID +KWorkItem:: +Handler( + _In_ PDEVICE_OBJECT IoObject, + _In_opt_ PVOID Context +) +/*++ + +Routine Description: + + Callback thunking function. + + Calls the callback handler registered in the constructor, if one exists. + Releases the reference on this object. + +Arguments: + + IoObject - + The parent device object. + Context - + An optional context object. + +Return Value: + + void + +--*/ +{ + // Get our "this" pointer (Me). + KWorkItem *Me = (KWorkItem *) Context; + + // Invoke the callback if one exists. + if( Me->m_Callback ) + { + Me->m_Callback( IoObject, Me->m_Context ); + } + + // Unlock the work item; allow for destruction or re-enqueing. + Me->Release(); +} -- cgit v1.3.1