本文将讲解DriverSync驱动代码,并比较它与AutoSync的差异。
一、代码比较
先借助BeyondCompare工具比较driversync和autosync工程,如下:
从上图可知(主要观察颜色和中间一列):
1)driver.c文件的代码几乎相同,不同的是driversync的driver.h中多定义了一个Request_context结构体。
2)device.c文件的代码略有不同,driversync添加了对Request_Context的初始化,仅此而已。
3)queue.c文件中的代码差异比较大。回顾一下第一篇中的readme:
In the AutoSync version of the sample, the queue is created with WdfSynchronizationScopeQueue so that I/O callbacks including cancel routine are synchronized with a queue-level lock. Since timer is parented to queue and by default timer objects are created with AutomaticSerialization set to **TRUE**, timer DPC callbacks will be serialized with EvtIoRead, EvtIoWrite and Cancel Routine.
In the DriverSync version of the sample, the queue is created with WdfSynchronizationScopeNone, so that the framework does not provide any synchronization. The driver synchronizes the I/O callbacks, cancel routine and the timer DPC using a spinlock that it creates for this purp