134ca7a464a9ce8c692d786652c1164d28287ea1
2 * COPYRIGHT: See COPYING in the top level directory
4 * FILE: ntoskrnl/hal/x86/fmutex.c
5 * PURPOSE: Deprecated HAL Fast Mutex
6 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
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.
17 /* INCLUDES *****************************************************************/
23 #undef ExAcquireFastMutex
24 #undef ExReleaseFastMutex
26 /* FUNCTIONS *****************************************************************/
30 ExAcquireFastMutex(PFAST_MUTEX FastMutex
)
34 /* Raise IRQL to APC */
35 KeRaiseIrql(APC_LEVEL
, &OldIrql
);
37 /* Decrease the count */
38 if (InterlockedDecrement(&FastMutex
->Count
))
40 /* Someone is still holding it, use slow path */
41 FastMutex
->Contention
++;
42 KeWaitForSingleObject(&FastMutex
->Event
,
49 /* Set the owner and IRQL */
50 FastMutex
->Owner
= KeGetCurrentThread();
51 FastMutex
->OldIrql
= OldIrql
;
56 ExReleaseFastMutex(PFAST_MUTEX FastMutex
)
61 FastMutex
->Owner
= (PVOID
)1;
62 OldIrql
= FastMutex
->OldIrql
;
64 /* Increase the count */
65 if (InterlockedIncrement(&FastMutex
->Count
) <= 0)
67 /* Someone was waiting for it, signal the waiter */
68 KeSetEventBoostPriority(&FastMutex
->Event
, IO_NO_INCREMENT
);
77 ExiTryToAcquireFastMutex(PFAST_MUTEX FastMutex
)
81 /* Raise to APC_LEVEL */
82 KeRaiseIrql(APC_LEVEL
, &OldIrql
);
84 /* Check if we can quickly acquire it */
85 if (InterlockedCompareExchange(&FastMutex
->Count
, 0, 1) == 1)
87 /* We have, set us as owners */
88 FastMutex
->Owner
= KeGetCurrentThread();
89 FastMutex
->OldIrql
= OldIrql
;
94 /* Acquire attempt failed */