d2ea93bd9177d027ea5323fa12e12ae0390e7faf
[reactos.git] / reactos / hal / halx86 / generic / spinlock.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/hal/x86/spinlock.c
6 * PURPOSE: Implements spinlocks
7 * PROGRAMMER: David Welch (welch@cwcom.net)
8 * Eric Kohl (ekohl@rz-online.de)
9 * UPDATE HISTORY:
10 * 09/06/2000 Created
11 */
12
13 /*
14 * NOTE: On a uniprocessor machine spinlocks are implemented by raising
15 * the irq level
16 */
17
18 /* INCLUDES ****************************************************************/
19
20 #include <ddk/ntddk.h>
21 #include <internal/ps.h>
22
23 #include <internal/debug.h>
24
25 /* Hmm, needed for KDBG := 1. Why? */
26 #undef KeGetCurrentIrql
27
28 /* FUNCTIONS ***************************************************************/
29
30 VOID STDCALL
31 KeAcquireSpinLock (
32 PKSPIN_LOCK SpinLock,
33 PKIRQL OldIrql
34 )
35 /*
36 * FUNCTION: Acquires a spinlock
37 * ARGUMENTS:
38 * SpinLock = Spinlock to acquire
39 * OldIrql (OUT) = Caller supplied storage for the previous irql
40 */
41 {
42 *OldIrql = KfAcquireSpinLock(SpinLock);
43 }
44
45 KIRQL FASTCALL
46 KeAcquireSpinLockRaiseToSynch (
47 PKSPIN_LOCK SpinLock
48 )
49 {
50 KIRQL OldIrql;
51
52 OldIrql = KfRaiseIrql(SYNCH_LEVEL);
53 KiAcquireSpinLock(SpinLock);
54
55 return OldIrql;
56 }
57
58 VOID STDCALL
59 KeReleaseSpinLock (
60 PKSPIN_LOCK SpinLock,
61 KIRQL NewIrql
62 )
63 /*
64 * FUNCTION: Releases a spinlock
65 * ARGUMENTS:
66 * SpinLock = Spinlock to release
67 * NewIrql = Irql level before acquiring the spinlock
68 */
69 {
70 KfReleaseSpinLock(SpinLock, NewIrql);
71 }
72
73 KIRQL FASTCALL
74 KfAcquireSpinLock (
75 PKSPIN_LOCK SpinLock
76 )
77 {
78 KIRQL OldIrql;
79
80 ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
81
82 OldIrql = KfRaiseIrql(DISPATCH_LEVEL);
83 KiAcquireSpinLock(SpinLock);
84
85 return OldIrql;
86 }
87
88 VOID FASTCALL
89 KfReleaseSpinLock (
90 PKSPIN_LOCK SpinLock,
91 KIRQL NewIrql
92 )
93 /*
94 * FUNCTION: Releases a spinlock
95 * ARGUMENTS:
96 * SpinLock = Spinlock to release
97 * NewIrql = Irql level before acquiring the spinlock
98 */
99 {
100 ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL || KeGetCurrentIrql() == SYNCH_LEVEL);
101 KiReleaseSpinLock(SpinLock);
102 KfLowerIrql(NewIrql);
103 }
104
105
106 /*
107 * @unimplemented
108 */
109 VOID
110 FASTCALL
111 KeAcquireInStackQueuedSpinLock(
112 IN PKSPIN_LOCK SpinLock,
113 IN PKLOCK_QUEUE_HANDLE LockHandle
114 )
115 {
116 UNIMPLEMENTED;
117 }
118
119
120 /*
121 * @unimplemented
122 */
123 VOID
124 FASTCALL
125 KeReleaseInStackQueuedSpinLock(
126 IN PKLOCK_QUEUE_HANDLE LockHandle
127 )
128 {
129 UNIMPLEMENTED;
130 }
131
132 /* EOF */