Merge 13159:13510 from trunk
[reactos.git] / reactos / ntoskrnl / ex / fmutex.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ex/fmutex.c
6 * PURPOSE: Implements fast mutexes
7 *
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #include <internal/debug.h>
15
16 /* FUNCTIONS *****************************************************************/
17
18 /*
19 * @implemented
20 */
21 VOID FASTCALL
22 ExAcquireFastMutexUnsafe(PFAST_MUTEX FastMutex)
23 {
24 ASSERT(FastMutex->Owner != KeGetCurrentThread());
25 InterlockedIncrementUL(&FastMutex->Contention);
26 while (InterlockedExchange(&FastMutex->Count, 0) == 0)
27 {
28 KeWaitForSingleObject(&FastMutex->Event,
29 Executive,
30 KernelMode,
31 FALSE,
32 NULL);
33 }
34 InterlockedDecrementUL(&FastMutex->Contention);
35 FastMutex->Owner = KeGetCurrentThread();
36 }
37
38 /*
39 * @implemented
40 */
41 VOID FASTCALL
42 ExReleaseFastMutexUnsafe(PFAST_MUTEX FastMutex)
43 {
44 ASSERT(FastMutex->Owner == KeGetCurrentThread());
45 FastMutex->Owner = NULL;
46 InterlockedExchange(&FastMutex->Count, 1);
47 if (FastMutex->Contention > 0)
48 {
49 KeSetEvent(&FastMutex->Event, 0, FALSE);
50 }
51 }
52
53 /* EOF */