The OP did not intimate what the locks were for AFAIK. Moreover, spinlocks
rarely protect ‘code’. They protect data - and in particularly the
consitency of update and access to the state of something from operations
performed on multiple processors.
This construct of nested locks is almost always necessary for any assemblage
of objects with a parent-child relationship where the parent state and child
state are indpendently protected.
Releasing locks out of LiFo order, however, does not seem like a very usual
case however but nested locks are not at all uncommon or an indication of
uncessary complexity.
The only restriction on spinlock acquisition AFAIK is that the processor
acquiring the spinlock must be at or below the lock IRQL. If the lock is
not already owned by another processor, ownership is granted; otherwise, the
processor spins until ownership is granted. There is no implicit or
explicit prohibition or impossiblity to acquiring the second lock from
another CPU without acquiring the first that I have ever seen stated.
-dave
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Friday, May 18, 2007 11:26 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] KeAcquireSpinLock vs KeAcquireSpinLockAtDPC
Why the inner lock is totally unnecessary?
Simply because no one, apart from outer lock holder, is able to acquire it.
Therefore, all code that inner lock protects is already protected by outer
one anyway, so that inner lock is just unnecessary.
Think about it carefully, and you will understand it…
What use case you are thinking ?
I think of some *theoretical* case when something happens,first, in between
acquisition of lock1 and lock2, and, second, while lock1 has been released
but lock2 is still being held . To be honest, in practical terms I just
cannot imagine the situation when such approach may give you anything, apart
from unnecessary complexity and potential bugs, although there is no logical
inconsistency in it - logical consistency of the code does not necessarily
imply reasonable design. My statement refers strictly to this theoretical
case and not to the sample code - using 2 locks in it is just unnnecessary
here .
Anton Bassov
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer