Interrupt SpinLock under Win2k - part 2

Hi!

Sorry for the 2 mails on the same topic directly following each other
(I assume they will), our mail system seems to not send mails out
today so I think they’ll all go out tomorrow.

To synchronize access to data shared with the ISR, can (may) one just
do something like:

//anywhere in nonpaged pool, properly aligned
static ULONG g_nMyLockVar = 0;

KIRQL oldIrql = KeRaiseIrql( MyDIRQL );

while( InterlockedCompareExchange( &g_nMyLockVar, 1, 0 ) )
/* spin */ ;

// do stuff

ULONG nTest = InterlockedCompareExchange( &g_nMyLockVar, 0, 1 );
ASSERT( nTest == 1 );
// or just InterlockedExchange( &g_nMyLockVar, 0 );

KeLowerIrql( oldIrql );

and have the same locking (without KeRaiseIrql & KeLowerIrql of
course) in the ISR?

That would really help me much, since I have a big number of
functions that I have to serialize with the ISR, and the driver needs
to run under windows 2000 where KeAcquireInterruptSpinLock is not
available…

I do not really care that there’s a slight performance hit because of
the double-locking (or the one single unneccesary locking in a single-
processor kernel), I’d just need to know if this could cause any
problems.

If there’s another way of getting KeAcquireInterruptSpinLock
functionality under windows 2000 (and above) of course I’d be happy to
know.

Regards,

Paul Groke

Is there some overwhelming reason why KeSynchronizeExecution will not work
for you?

By the way, spinning on the interlocked operation is not a good idea. A two
phased operation where the spin is on a non-interlocked operation is a
better approach.

=====================
Mark Roddy

-----Original Message-----
From: xxxxx@tab.at [mailto:xxxxx@tab.at]
Sent: Monday, June 07, 2004 7:33 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Interrupt SpinLock under Win2k - part 2

Hi!

Sorry for the 2 mails on the same topic directly following each other (I
assume they will), our mail system seems to not send mails out today so I
think they’ll all go out tomorrow.

To synchronize access to data shared with the ISR, can (may) one just do
something like:

//anywhere in nonpaged pool, properly aligned static ULONG g_nMyLockVar = 0;

KIRQL oldIrql = KeRaiseIrql( MyDIRQL );

while( InterlockedCompareExchange( &g_nMyLockVar, 1, 0 ) )
/* spin */ ;

// do stuff

ULONG nTest = InterlockedCompareExchange( &g_nMyLockVar, 0, 1 ); ASSERT(
nTest == 1 ); // or just InterlockedExchange( &g_nMyLockVar, 0 );

KeLowerIrql( oldIrql );

and have the same locking (without KeRaiseIrql & KeLowerIrql of
course) in the ISR?

That would really help me much, since I have a big number of functions that
I have to serialize with the ISR, and the driver needs to run under windows
2000 where KeAcquireInterruptSpinLock is not available…

I do not really care that there’s a slight performance hit because of the
double-locking (or the one single unneccesary locking in a single- processor
kernel), I’d just need to know if this could cause any problems.

If there’s another way of getting KeAcquireInterruptSpinLock functionality
under windows 2000 (and above) of course I’d be happy to know.

Regards,

Paul Groke


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

> If there’s another way of getting KeAcquireInterruptSpinLock

functionality under windows 2000 (and above)

Yes. KeSynchronizeExecution.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com