ReactOS  0.4.15-dev-2522-g9e0a3cd
mxlockum.h
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 ModuleName:
6 
7  MxLockUm.h
8 
9 Abstract:
10 
11  User mode implementation of lock
12  class defined in MxLock.h
13 
14 Author:
15 
16 
17 
18 Revision History:
19 
20 
21 
22 --*/
23 
24 #pragma once
25 
26 typedef struct {
30 } MdLock;
31 
32 #include "DbgMacros.h"
33 #include "MxLock.h"
34 
35 __inline
37  )
38 {
40 
41  m_Lock.Initialized = false;
43 
45 }
46 
47 __inline
48 VOID
50  )
51 {
52  BOOL ret;
53 
55 
57 
58  //
59  // InitializeCriticalSectionAndSpinCount always returns TRUE on Vista+
60  // Assert this contract on checked builds using DBGFLAG macro.
61  //
62  if (ret) {
63  m_Lock.Initialized = true;
65  }
66 
68 }
69 
70 
71 __inline
72 VOID
73 #pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
74 MxLockNoDynam::Acquire(
76  )
77 {
79 
81 
82  DWORD threadId = GetCurrentThreadId();
83 
84  if (threadId == m_Lock.OwnerThreadId) {
85  Mx::MxAssertMsg("Recursive acquision of the lock is not allowed", FALSE);
86  }
87 
88  m_Lock.OwnerThreadId = threadId;
89 
91 }
92 
93 __inline
94 BOOLEAN
96  VOID
97  )
98 {
99  BOOLEAN acquired;
100 
102 
104 
105  if (acquired) {
106  DWORD threadId = GetCurrentThreadId();
107 
108  if (threadId == m_Lock.OwnerThreadId) {
109  Mx::MxAssertMsg("Recursive acquision of the lock is not allowed", FALSE);
110  }
111 
112  m_Lock.OwnerThreadId = threadId;
113  }
114 
115  return acquired;
116 }
117 
118 __inline
119 VOID
120 #pragma prefast(suppress:__WARNING_UNMATCHED_DEFN, "Can't apply kernel mode annotations.");
121 MxLockNoDynam::AcquireAtDpcLevel(
122  )
123 {
125 
126  KIRQL dontCare;
127 
128  Acquire(&dontCare);
129 }
130 
131 __inline
132 VOID
133 #pragma prefast(suppress:__WARNING_UNMATCHED_DEFN, "Can't apply kernel mode annotations.");
135  KIRQL NewIrql
136  )
137 {
139 
141 
142  m_Lock.OwnerThreadId = 0;
143 
145 }
146 
147 __inline
148 VOID
149 #pragma prefast(suppress:__WARNING_UNMATCHED_DEFN, "Can't apply kernel mode annotations.");
150 MxLockNoDynam::ReleaseFromDpcLevel(
151  )
152 {
154 
156 }
157 
158 __inline
159 VOID
161  )
162 {
164 
166  m_Lock.Initialized = false;
167 
169 }
170 
171 __inline
173  )
174 {
175  //
176  // PLEASE NOTE: shared code must not rely of d'tor uninitializing the
177  // lock. d'tor may not be invoked if the event is used in a structure
178  // which is allocated/deallocated using MxPoolAllocate/Free instead of
179  // new/delete
180  //
181 
182  if (m_Lock.Initialized) {
183  this->Uninitialize();
184  }
185 }
BOOL WINAPI InitializeCriticalSectionAndSpinCount(OUT LPCRITICAL_SECTION lpCriticalSection, IN DWORD dwSpinCount)
Definition: synch.c:765
KSPIN_LOCK MdLock
Definition: mxlockkm.h:28
__inline ~MxLock()
Definition: mxlockkm.h:111
MdLock m_Lock
Definition: mxlock.h:40
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static __inline VOID MxAssert(__in BOOLEAN Condition)
Definition: mxgeneralkm.h:165
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
CRITICAL_SECTION Lock
Definition: mxlockum.h:27
#define __out
Definition: dbghelp.h:62
unsigned char BOOLEAN
DWORD OwnerThreadId
Definition: mxlockum.h:29
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:458
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define SET_DBGFLAG_INITIALIZED
Definition: dbgmacros.h:59
__inline MxLock()
Definition: mxlockkm.h:33
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CLEAR_DBGFLAG_INITIALIZED
Definition: dbgmacros.h:60
__inline VOID Uninitialize()
Definition: mxlockkm.h:104
#define ASSERT_DBGFLAG_NOT_INITIALIZED
Definition: dbgmacros.h:61
int ret
BOOL WINAPI TryEnterCriticalSection(LPCRITICAL_SECTION)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
bool Initialized
Definition: mxlockum.h:28
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
static __inline VOID MxAssertMsg(__in LPSTR Message, __in BOOLEAN Condition)
Definition: mxgeneralkm.h:176
_In_ BOOLEAN Release
Definition: cdrom.h:920
#define BOOLEAN
Definition: pedump.c:73
#define ASSERT_DBGFLAG_INITIALIZED
Definition: dbgmacros.h:58
CHECK_RETURN_IF_USER_MODE __inline BOOLEAN TryToAcquire(VOID)
Definition: mxlockum.h:95
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
__inline VOID Initialize()
Definition: mxlockkm.h:43
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114