Initial revision
[reactos.git] / reactos / ntoskrnl / hal / x86 / spinlock.c
1 /*
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)
7 * UPDATE HISTORY:
8 * 3/6/98: Created
9 */
10
11 /*
12 * NOTE: On a uniprocessor machine spinlocks are implemented by raising
13 * the irq level
14 */
15
16 /* INCLUDES ****************************************************************/
17
18 #include <windows.h>
19 #include <ddk/ntddk.h>
20
21 #include <internal/debug.h>
22
23 /* FUNCTIONS ***************************************************************/
24
25 BOOLEAN KeSynchronizeExecution(PKINTERRUPT Interrupt,
26 PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
27 PVOID SynchronizeContext)
28 /*
29 * FUNCTION: Synchronizes the execution of a given routine with the ISR
30 * of a given interrupt object
31 * ARGUMENTS:
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
37 */
38 {
39 KIRQL oldlvl;
40 BOOLEAN ret;
41
42 KeRaiseIrql(Interrupt->SynchLevel,&oldlvl);
43 KeAcquireSpinLockAtDpcLevel(Interrupt->IrqLock);
44
45 ret = SynchronizeRoutine(SynchronizeContext);
46
47 KeReleaseSpinLockFromDpcLevel(Interrupt->IrqLock);
48 KeLowerIrql(oldlvl);
49
50 return(ret);
51 }
52
53 VOID KeInitializeSpinLock(PKSPIN_LOCK SpinLock)
54 /*
55 * FUNCTION: Initalizes a spinlock
56 * ARGUMENTS:
57 * SpinLock = Caller supplied storage for the spinlock
58 */
59 {
60 SpinLock->irql = DISPATCH_LEVEL;
61 }
62
63 VOID KeAcquireSpinLockAtDpcLevel(PKSPIN_LOCK SpinLock)
64 /*
65 * FUNCTION: Acquires a spinlock when the caller is already running at
66 * dispatch level
67 * ARGUMENTS:
68 * SpinLock = Spinlock to acquire
69 */
70 {
71 }
72
73 VOID KeReleaseSpinLockFromDpcLevel(PKSPIN_LOCK SpinLock)
74 /*
75 * FUNCTION: Releases a spinlock when the caller was running at dispatch
76 * level before acquiring it
77 * ARGUMENTS:
78 * SpinLock = Spinlock to release
79 */
80 {
81 }
82
83 VOID KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
84 /*
85 * FUNCTION: Acquires a spinlock
86 * ARGUMENTS:
87 * SpinLock = Spinlock to acquire
88 * OldIrql (OUT) = Caller supplied storage for the previous irql
89 */
90 {
91 KeRaiseIrql(DISPATCH_LEVEL,OldIrql);
92 }
93
94 VOID KeReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL NewIrql)
95 /*
96 * FUNCTION: Releases a spinlock
97 * ARGUMENTS:
98 * SpinLock = Spinlock to release
99 * NewIrql = Irql level before acquiring the spinlock
100 */
101 {
102 KeLowerIrql(NewIrql);
103 }
104