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:

bulletNDIS_RW_LOCK - Available on Windows XP through Windows 7.
bulletNDIS_RW_LOCK_EX - Available on Windows 7 only. (An optimization for >64 processors.)

Search the MSDN for "NDIS Read Write Lock Interface" for NDIS_RW_LOCK.

Search the MSDN for "NDIS 6.20 Read Write Lock Interface" for NDIS_RW_LOCK_EX.

I hope that this is helpful to some of you.

 

Topic Status

August 19, 2011 Information posted.
 

PCAUSA Home · Privacy Statement · Products · Ordering · Support · Utilities · Resources
Mailing Lists  · PCAUSA Newsletter · PCAUSA Discussion List
Rawether for Windows, Rawether .NET, WinDis 32 and NDIS Press are trademarks of Printing Communications Assoc., Inc. (PCAUSA)
Microsoft, MS, Windows, Windows Vista, Windows 95, Windows 98, Windows Millennium, Windows 2000, and Win32 are registered trademarks and Visual C++ and Windows NT are trademarks of the Microsoft Corporation.
Copyright © 1996-2012 Printing Communications Assoc., Inc. (PCAUSA)
Last modified: January 01, 2012