Fix really stupid typo (thanks Hartmut)
[reactos.git] / reactos / hal / halx86 / generic / fmutex.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS HAL
4 * FILE: ntoskrnl/hal/x86/fmutex.c
5 * PURPOSE: Deprecated HAL Fast Mutex
6 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
7 */
8
9 /*
10 * NOTE: Even HAL itself has #defines to use the Exi* APIs inside NTOSKRNL.
11 * These are only exported here for compatibility with really old
12 * drivers. Also note that in theory, these can be made much faster
13 * by using assembly and inlining all the operations, including
14 * raising and lowering irql.
15 */
16
17 /* INCLUDES *****************************************************************/
18
19 #include <hal.h>
20 #define NDEBUG
21 #include <debug.h>
22
23 #undef ExAcquireFastMutex
24 #undef ExReleaseFastMutex
25 #undef ExTryToAcquireFastMutex
26
27 /* FUNCTIONS *****************************************************************/
28
29 VOID
30 FASTCALL
31 ExAcquireFastMutex(PFAST_MUTEX FastMutex)
32 {
33 KIRQL OldIrql;
34
35 /* Raise IRQL to APC */
36 OldIrql = KfRaiseIrql(APC_LEVEL);
37
38 /* Decrease the count */
39 if (InterlockedDecrement(&FastMutex->Count))
40 {
41 /* Someone is still holding it, use slow path */
42 FastMutex->Contention++;
43 KeWaitForSingleObject(&FastMutex->Gate,
44 WrExecutive,
45 KernelMode,
46 FALSE,
47 NULL);
48 }
49
50 /* Set the owner and IRQL */
51 FastMutex->Owner = KeGetCurrentThread();
52 FastMutex->OldIrql = OldIrql;
53 }
54
55 VOID
56 FASTCALL
57 ExReleaseFastMutex(PFAST_MUTEX FastMutex)
58 {
59 /* Erase the owner */
60 FastMutex->Owner = (PVOID)1;
61
62 /* Increase the count */
63 if (InterlockedIncrement(&FastMutex->Count) <= 0)
64 {
65 /* Someone was waiting for it, signal the waiter */
66 KeSetEventBoostPriority(&FastMutex->Gate, IO_NO_INCREMENT);
67 }
68
69 /* Lower IRQL back */
70 KfLowerIrql(FastMutex->OldIrql);
71 }
72
73 BOOLEAN
74 FASTCALL
75 ExTryToAcquireFastMutex(PFAST_MUTEX FastMutex)
76 {
77 KIRQL OldIrql;
78
79 /* Raise to APC_LEVEL */
80 OldIrql = KfRaiseIrql(APC_LEVEL);
81
82 /* Check if we can quickly acquire it */
83 if (InterlockedCompareExchange(&FastMutex->Count, 0, 1) == 1)
84 {
85 /* We have, set us as owners */
86 FastMutex->Owner = KeGetCurrentThread();
87 return TRUE;
88 }
89 else
90 {
91 /* Acquire attempt failed */
92 KfLowerIrql(OldIrql);
93 return FALSE;
94 }
95 }
96
97 /* EOF */