NDIS 6 Read/Write Lock
(It's not just for NDIS...)

Introduction
Use of spin locks is pervasive in many NDIS components. Spin locks provide a
simple and safe way to synchronize access to data that must be accessed at IRQL
<= DISPATCH_LEVEL.
The cost of acquiring and releasing a spin lock is small. It is the
synchronization method of choice when the time spent within the lock is
relatively small or there is no alternative.
However, there are some situations that beg for a system provided
reader/writer lock that can be used at IRQL == DISPATCH_LEVEL as well as at IRQL
< DISPATCH_LEVEL with multiple readers at any IRQL.
For example, consider a design that includes a fairly large hash table. Table
update operations are made infrequently at IRQL == PASSIVE_LEVEL and are time
consuming because they may rebalance the tree. However table searches are made
very frequently at IRQL == DISPATCH_LEVEL and are very quick. In this case a R/W
lock that would use Write access for the updates and Read access for the
searches might be a desirable alternative to a spin lock.
Although sometimes overlooked (at least by this writer...), the NDIS library
provides a SMP-safe Read/Write lock facility. As a bonus, the NDIS Read/Write
lock can be used in non-NDIS drivers. Much better than creating your own R/W
lock with these characteristics - especially in a hot-add and processor group is
considered.
There are two generation of the NDIS Read Write Lock Interface: