Windows Driver Samples剖析之Echo(六)

本文对比分析了Windows Driver Samples中的DriverSync和AutoSync驱动,重点探讨了两者在IO回调、DPC和取消例程同步方式的差异。DriverSync使用自定义spin lock进行同步,而AutoSync依赖框架的自动同步。同步机制涉及队列同步属性设置、spin lock的创建和使用,以及请求的取消所有权计数。
摘要由CSDN通过智能技术生成

        本文将讲解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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值