WINDOWS NT Device Driver Development Basis (6)

zhaozj2021-02-11  224

1.3.8 Synchronization

If the driver is likely to have multiple parts at a moment, if there is an interrupt processing, or

There are multiple devices, etc., and access to public data or code needs to be synchronized. Method

i) self-spin lock (Spinlock)

The driver can call KeinitialIzesPinLock when initialization creates this object. In any code segment

Before accessing the protected data, call the keAcquirespinlock to try to get the ownership of the object, if successful

This segment code is upgraded to Dispatch_level, and data is performed. Beelese is required after the visit is completed.

SpinLock releases ownership and running level is also recovered. This method only applies to the synchronous run level less than or equal to DISP

Atch_level code, mainly used for multi-CPU. In addition, there is an interrupt self-locking for processing and interrupt processing.

Process synchronization, you can upgrade a lower level code to interrupt DIRQL that needs to be synchronized.

II) Controller

This object is primarily used to synchronize multiple devices in a driver to ensure that they can access specific

Code or data. This object is created in the driver initialization call IOCREATECONTROLLER. Equipment in Starti

o Call the IOAllocateController request to get the monopoller of the Controller object. Call i after use

Ofreecontroller is released. Calling IodeleteController when the driver stops deletes the object from memory. Should

Object has a pointer controlleRextension pointing to a structure defined by the driver, where this is saved.

The public data of the motion.

III) Adapter

This object is used to synchronize multiple devices (not necessarily in one driver) to the DMA channel. This object

Automatically created automatically when the system starts detecting hardware. The driver calls the HalgetAdapter when initialization.

Pointer. The device calls IOALLOCATEADAPTERCHANNEL in the Startio process to obtain monopolis of DMA channels

Right, then start transmitting data. The iOfreeControllerChannel release the DMA channel after using it.

IV) DPC

Since objects in the DPC queue are always processed sequentially, you can also make the code that needs to be synchronized.

The DPC process requires call to place the corresponding DPC object to the end of the queue upon time.

v) Other

Similar to user mode applications, drivers can also use multithreaded, and provide a set of synchronization

Objects such as Event, Mutex, Semaphore, Timer, Thread. Where Event object can be named, different

The driver can synchronize access to public data with the same name.

-

转载请注明原文地址:https://www.9cbs.com/read-3788.html

New Post(0)