Tech Support > Microsoft Windows > Drivers > How to replace Spinlock ?
How to replace Spinlock ?
Posted by satheesh on February 28th, 2005


Hi All,

I have to port a WDM video capture driver to WinCE
4.2....i am finding frequent occurence of KeAcquireSpinLock and following
release ...How can i replace this kernel mode spinlock to a user mode lock
which will work fine in WinCE since drivers work in user mode over
there...I would also like to get some general tips of porting a WDM driver
to WinCE .Looking forward for your
help..Thanks in Advance ..

Cheers
Satheesh



Posted by Steve on March 1st, 2005


I would image that you would use events objects instead.

Write your own lock functions. When one thread aquires
lock the event object is cleared. Other threads
attempting to aquire lock wait for the event object to be
signaled. When first thread finishes with protocted data
it releases the lock and sets the event object to
signaled, then one of the other threads gets woken up
and then aquires the lock.

example ...

KeInitializeEvent(&LockEvent, SynchronizationEvent, TRUE);

int AquireLock(void)
{
// wait for object to be signaled ...
NTSTATUS ntStatus = KeWaitForSingleObject(&LockEvent,...)
//
// object is autoreset so is now cleared and
// lock is aquired - other threads call AquireLock
// and go to sleep at KeWaitForSingleObject() waiting
// for event to get signaled.
}

int ReleaseLock(void)
{
// release lock - set event - other waiting threads
// will get woken up
KeSetEvent(LockEvent,...)
}

Steve.


Similar Posts