2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: kernel/hal/x86/spinlock.c
5 * PURPOSE: Implements spinlocks
6 * PROGRAMMER: David Welch (welch@mcmail.com)
12 * NOTE: On a uniprocessor machine spinlocks are implemented by raising
16 /* INCLUDES ****************************************************************/
19 #include <ddk/ntddk.h>
21 #include <internal/debug.h>
23 /* FUNCTIONS ***************************************************************/
25 BOOLEAN
KeSynchronizeExecution(PKINTERRUPT Interrupt
,
26 PKSYNCHRONIZE_ROUTINE SynchronizeRoutine
,
27 PVOID SynchronizeContext
)
29 * FUNCTION: Synchronizes the execution of a given routine with the ISR
30 * of a given interrupt object
32 * Interrupt = Interrupt object to synchronize with
33 * SynchronizeRoutine = Routine to call whose execution is
34 * synchronized with the ISR
35 * SynchronizeContext = Parameter to pass to the synchronized routine
36 * RETURNS: TRUE if the operation succeeded
42 KeRaiseIrql(Interrupt
->SynchLevel
,&oldlvl
);
43 KeAcquireSpinLockAtDpcLevel(Interrupt
->IrqLock
);
45 ret
= SynchronizeRoutine(SynchronizeContext
);
47 KeReleaseSpinLockFromDpcLevel(Interrupt
->IrqLock
);
53 VOID
KeInitializeSpinLock(PKSPIN_LOCK SpinLock
)
55 * FUNCTION: Initalizes a spinlock
57 * SpinLock = Caller supplied storage for the spinlock
60 SpinLock
->irql
= DISPATCH_LEVEL
;
63 VOID
KeAcquireSpinLockAtDpcLevel(PKSPIN_LOCK SpinLock
)
65 * FUNCTION: Acquires a spinlock when the caller is already running at
68 * SpinLock = Spinlock to acquire
73 VOID
KeReleaseSpinLockFromDpcLevel(PKSPIN_LOCK SpinLock
)
75 * FUNCTION: Releases a spinlock when the caller was running at dispatch
76 * level before acquiring it
78 * SpinLock = Spinlock to release
83 VOID
KeAcquireSpinLock(PKSPIN_LOCK SpinLock
, PKIRQL OldIrql
)
85 * FUNCTION: Acquires a spinlock
87 * SpinLock = Spinlock to acquire
88 * OldIrql (OUT) = Caller supplied storage for the previous irql
91 KeRaiseIrql(DISPATCH_LEVEL
,OldIrql
);
94 VOID
KeReleaseSpinLock(PKSPIN_LOCK SpinLock
, KIRQL NewIrql
)
96 * FUNCTION: Releases a spinlock
98 * SpinLock = Spinlock to release
99 * NewIrql = Irql level before acquiring the spinlock
102 KeLowerIrql(NewIrql
);