+VOID
+FASTCALL
+KeAcquireQueuedSpinLockAtDpcLevel(IN PKLOCK_QUEUE_HANDLE LockHandle)
+{
+#ifdef CONFIG_SMP
+ PKSPIN_LOCK_QUEUE Prev;
+
+ /* Set the new lock */
+ Prev = (PKSPIN_LOCK_QUEUE)
+ InterlockedExchange((PLONG)LockHandle->LockQueue.Lock,
+ (LONG)LockHandle);
+ if (!Prev)
+ {
+ /* There was nothing there before. We now own it */
+ *(ULONG_PTR*)&LockHandle->LockQueue.Lock |= LQ_OWN;
+ return;
+ }
+
+ /* Set the wait flag */
+ *(ULONG_PTR*)&LockHandle->LockQueue.Lock |= LQ_WAIT;
+
+ /* Link us */
+ Prev->Next = (PKSPIN_LOCK_QUEUE)LockHandle;
+
+ /* Loop and wait */
+ while ( *(ULONG_PTR*)&LockHandle->LockQueue.Lock & LQ_WAIT) YieldProcessor();
+ return;
+#endif
+}
+
+VOID
+FASTCALL
+KeReleaseQueuedSpinLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE LockHandle)
+{
+#ifdef CONFIG_SMP
+ KSPIN_LOCK LockVal;
+ PKSPIN_LOCK_QUEUE Waiter;
+
+ /* Remove own and wait flags */
+ *(ULONG_PTR*)&LockHandle->LockQueue.Lock &= ~(LQ_OWN | LQ_WAIT);
+ LockVal = *LockHandle->LockQueue.Lock;
+
+ /* Check if we already own it */
+ if (LockVal == (KSPIN_LOCK)LockHandle)
+ {
+ /* Disown it */
+ LockVal = (KSPIN_LOCK)
+ InterlockedCompareExchangePointer(LockHandle->LockQueue.Lock,
+ NULL,
+ LockHandle);
+ }
+ if (LockVal == (KSPIN_LOCK)LockHandle) return;
+
+ /* Need to wait for it */
+ Waiter = LockHandle->LockQueue.Next;
+ while (!Waiter)
+ {
+ YieldProcessor();
+ Waiter = LockHandle->LockQueue.Next;
+ }
+
+ /* It's gone */
+ *(ULONG_PTR*)&Waiter->Lock ^= (LQ_OWN | LQ_WAIT);
+ LockHandle->LockQueue.Next = NULL;
+#endif
+}
+