ReactOS  0.4.14-dev-991-g696cdc6
fmutex.c File Reference
#include <hal.h>
#include <debug.h>
Include dependency graph for fmutex.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID FASTCALL ExAcquireFastMutex (PFAST_MUTEX FastMutex)
 
VOID FASTCALL ExReleaseFastMutex (PFAST_MUTEX FastMutex)
 
BOOLEAN FASTCALL ExiTryToAcquireFastMutex (PFAST_MUTEX FastMutex)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 20 of file fmutex.c.

Function Documentation

◆ ExAcquireFastMutex()

VOID FASTCALL ExAcquireFastMutex ( PFAST_MUTEX  FastMutex)

Definition at line 30 of file fmutex.c.

31 {
32  KIRQL OldIrql;
33 
34  /* Raise IRQL to APC */
36 
37  /* Decrease the count */
38  if (InterlockedDecrement(&FastMutex->Count))
39  {
40  /* Someone is still holding it, use slow path */
41  FastMutex->Contention++;
42  KeWaitForSingleObject(&FastMutex->Event,
44  KernelMode,
45  FALSE,
46  NULL);
47  }
48 
49  /* Set the owner and IRQL */
50  FastMutex->Owner = KeGetCurrentThread();
51  FastMutex->OldIrql = OldIrql;
52 }
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define KeGetCurrentThread
Definition: hal.h:44
#define APC_LEVEL
Definition: env_spec_w32.h:695

◆ ExiTryToAcquireFastMutex()

BOOLEAN FASTCALL ExiTryToAcquireFastMutex ( PFAST_MUTEX  FastMutex)

Definition at line 77 of file fmutex.c.

78 {
79  KIRQL OldIrql;
80 
81  /* Raise to APC_LEVEL */
83 
84  /* Check if we can quickly acquire it */
85  if (InterlockedCompareExchange(&FastMutex->Count, 0, 1) == 1)
86  {
87  /* We have, set us as owners */
88  FastMutex->Owner = KeGetCurrentThread();
89  FastMutex->OldIrql = OldIrql;
90  return TRUE;
91  }
92  else
93  {
94  /* Acquire attempt failed */
96  return FALSE;
97  }
98 }
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define TRUE
Definition: types.h:120
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define InterlockedCompareExchange
Definition: interlocked.h:104
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define KeGetCurrentThread
Definition: hal.h:44
#define APC_LEVEL
Definition: env_spec_w32.h:695

◆ ExReleaseFastMutex()

VOID FASTCALL ExReleaseFastMutex ( PFAST_MUTEX  FastMutex)

Definition at line 56 of file fmutex.c.

57 {
58  KIRQL OldIrql;
59 
60  /* Erase the owner */
61  FastMutex->Owner = (PVOID)1;
62  OldIrql = FastMutex->OldIrql;
63 
64  /* Increase the count */
65  if (InterlockedIncrement(&FastMutex->Count) <= 0)
66  {
67  /* Someone was waiting for it, signal the waiter */
68  KeSetEventBoostPriority(&FastMutex->Event, IO_NO_INCREMENT);
69  }
70 
71  /* Lower IRQL back */
73 }
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
UCHAR KIRQL
Definition: env_spec_w32.h:591
void * PVOID
Definition: retypes.h:9
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define InterlockedIncrement
Definition: armddk.h:53
#define IO_NO_INCREMENT
Definition: iotypes.h:566
VOID NTAPI KeSetEventBoostPriority(IN PKEVENT Event, IN PKTHREAD *WaitingThread OPTIONAL)
Definition: eventobj.c:229