ReactOS 0.4.16-dev-91-g764881a
fxspinlock.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxSpinLock.cpp
8
9Abstract:
10
11 This module implements FxSpinLock
12
13Author:
14
15
16
17Environment:
18
19 Both kernel and user mode
20
21Revision History:
22
23--*/
24
25#include "fxsupportpch.hpp"
26#include "fxspinlock.hpp"
27
28extern "C" {
29// #include "FxSpinLock.tmh"
30}
31
33 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
34 __in USHORT ExtraSize
35 ) :
36 FxObject(FX_TYPE_SPIN_LOCK, COMPUTE_OBJECT_SIZE(sizeof(FxSpinLock), ExtraSize), FxDriverGlobals)
37{
38 FX_SPIN_LOCK_HISTORY* pHistory;
39
40 m_Irql = 0;
42
43 pHistory = GetHistory();
44
45 if (pHistory != NULL) {
46 RtlZeroMemory(pHistory, sizeof(FX_SPIN_LOCK_HISTORY));
47
48 pHistory->CurrentHistory = &pHistory->History[0];
49 }
50}
51
52
55VOID
56FxSpinLock::AcquireLock(
57 __in PVOID CallersAddress
58 )
59{
60 PFX_SPIN_LOCK_HISTORY pHistory;
61 KIRQL irql;
62
63 m_SpinLock.Acquire(&irql);
64
65 m_Irql = irql;
66
67 pHistory = GetHistory();
68
69 if (pHistory != NULL) {
71
72 //
73 // This assert should never fire here, but this helps track ownership
74 // in the case of a release without an acquire.
75 //
76 ASSERT(pHistory->OwningThread == NULL);
78
79 pCur = pHistory->CurrentHistory;
80
81 Mx::MxQueryTickCount(&pCur->AcquiredAtTime);
82 pCur->CallersAddress = CallersAddress;
83 }
84}
85
87VOID
88FxSpinLock::ReleaseLock(
89 VOID
90 )
91{
92 PFX_SPIN_LOCK_HISTORY pHistory;
93
94 pHistory = GetHistory();
95
96 if (pHistory != NULL) {
99
100 if (pHistory->OwningThread != Mx::MxGetCurrentThread()) {
101 if (pHistory->OwningThread == NULL) {
104 "WDFSPINLOCK %p being released by thread 0x%p, but was "
105 "never acquired!", GetObjectHandle(), Mx::MxGetCurrentThread());
106 }
107 else {
110 "WDFSPINLOCK 0x%p not owned by thread 0x%p, owned by thread 0x%p",
112 pHistory->OwningThread);
113 }
114
118 0x1);
119 //
120 // Will not get here
121 //
122 return;
123 }
124
125 ASSERT(pHistory->OwningThread != NULL);
126
128
129 pCur = pHistory->CurrentHistory;
130 pCur->LockedDuraction = now.QuadPart - pCur->AcquiredAtTime.QuadPart;
131
132 pHistory->CurrentHistory++;
133 if (pHistory->CurrentHistory >=
135 pHistory->CurrentHistory = pHistory->History;
136 }
137
138 pHistory->OwningThread = NULL;
139 }
140
141 m_SpinLock.Release(m_Irql);
142}
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
MxLock m_SpinLock
Definition: fxspinlock.hpp:107
KIRQL m_Irql
Definition: fxspinlock.hpp:109
FxSpinLock(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ExtraSize)
Definition: fxspinlock.cpp:32
BOOLEAN m_InterruptLock
Definition: fxspinlock.hpp:118
PFX_SPIN_LOCK_HISTORY GetHistory(VOID)
Definition: fxspinlock.hpp:90
static __inline VOID MxQueryTickCount(__out PLARGE_INTEGER TickCount)
Definition: mxgeneralkm.h:116
static __inline MxThread MxGetCurrentThread()
Definition: mxgeneralkm.h:61
#define __in
Definition: dbghelp.h:35
#define TRACINGERROR
Definition: dbgtrace.h:63
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
KIRQL irql
Definition: wave.h:1
#define __drv_requiresIRQL(irql)
Definition: driverspecs.h:321
#define __drv_raisesIRQL(irql)
Definition: driverspecs.h:312
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
time_t now
Definition: finger.c:65
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
return pObject GetObjectHandle()
SINGLE_LIST_ENTRY * pCur
#define COMPUTE_OBJECT_SIZE(_rawObjectSize, _extraSize)
Definition: fxhandle.h:107
#define FX_SPIN_LOCK_NUM_HISTORY_ENTRIES
Definition: fxspinlock.hpp:21
@ FX_TYPE_SPIN_LOCK
Definition: fxtypes.h:77
#define FxVerifierBugCheck(FxDriverGlobals, Error,...)
Definition: fxverifier.h:58
#define ASSERT(a)
Definition: mode.c:44
unsigned short USHORT
Definition: pedump.c:61
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: fxspinlock.hpp:23
PFX_SPIN_LOCK_HISTORY_ENTRY CurrentHistory
Definition: fxspinlock.hpp:34
FX_SPIN_LOCK_HISTORY_ENTRY History[FX_SPIN_LOCK_NUM_HISTORY_ENTRIES]
Definition: fxspinlock.hpp:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
@ WDF_INVALID_LOCK_OPERATION
Definition: wdfbugcodes.h:68
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList