## The SPINLOCK Sample

The SPINLOCK Sample accompanies Chapter 3 and illustrates how to use in-stack queued spin locks in a system portable way. This sample was added to the 2d edition.

The sample includes one component:

- SPINLOCK.SYS is a WDM driver for a non-existent hardware device.

### Building SPINLOCK

To build SPINLOCK.SYS, follow the general instructions for building a WDM sample. The Microsoft Visual C++ project file is named SPINLOCK.DSP.

### Testing SPINLOCK

Follow the general instructions for using FastInst in Windows XP or Windows 98/Me. The INF file is named SPINLOCK.INF.

I recommend that you have some means of viewing debug messages when you install this sample so that you can see whether the portable spinlock package has chosen to use regular spin locks or in-stack queued spin locks. You could, for example, download DbgView from http://www.sysinternals.com.

### Special Note:

The "portable" code in spinlock.cpp calls MmGetSystemRoutineAddress, which is not available in Windows 98/Me unless you ship wdmstub.sys with your driver.

### What to look for

The file spinlock.h declares a platform-portable DDI for accessing in-stack queued spin locks when they happen to be available. This file also contains usage instructions. StartDevice (ReadWrite.cpp) illustrates how to use these functions, which are implemented in spinlock.cpp. The latter file shows how to use MmGetSystemRoutineAddress, too.