ReactOS  0.4.15-dev-3182-g7b62228
fxspinlock.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxSpinLock.cpp
8 
9 Abstract:
10 
11  This module implements FxSpinLock
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Both kernel and user mode
20 
21 Revision History:
22 
23 --*/
24 
25 #include "fxsupportpch.hpp"
26 #include "fxspinlock.hpp"
27 
28 extern "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 
55 VOID
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 
87 VOID
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 }
PFX_SPIN_LOCK_HISTORY_ENTRY CurrentHistory
Definition: fxspinlock.hpp:34
KIRQL m_Irql
Definition: fxspinlock.hpp:109
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
static __inline VOID MxQueryTickCount(__out PLARGE_INTEGER TickCount)
Definition: mxgeneralkm.h:116
BOOLEAN m_InterruptLock
Definition: fxspinlock.hpp:118
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
FxSpinLock(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ExtraSize)
Definition: fxspinlock.cpp:32
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:290
KIRQL irql
Definition: wave.h:1
Definition: fxspinlock.hpp:23
#define FxVerifierBugCheck(FxDriverGlobals, Error,...)
Definition: fxverifier.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
pPkgPnp m_DeviceInterfaceLock ReleaseLock(pFxDriverGlobals)
time_t now
Definition: finger.c:65
PVOID __inline GetObjectHandle(VOID)
Definition: fxobject.hpp:603
MxLock m_SpinLock
Definition: fxspinlock.hpp:107
#define COMPUTE_OBJECT_SIZE(_rawObjectSize, _extraSize)
Definition: fxhandle.h:107
#define ASSERT(a)
Definition: mode.c:44
#define FX_SPIN_LOCK_NUM_HISTORY_ENTRIES
Definition: fxspinlock.hpp:21
pPkgPnp m_DeviceInterfaceLock AcquireLock(pFxDriverGlobals)
PFX_SPIN_LOCK_HISTORY GetHistory(VOID)
Definition: fxspinlock.hpp:90
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
__drv_requiresIRQL(DISPATCH_LEVEL) VOID FxSpinLock
Definition: fxspinlock.cpp:86
static __inline MxThread MxGetCurrentThread()
Definition: mxgeneralkm.h:61
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
unsigned short USHORT
Definition: pedump.c:61
SINGLE_LIST_ENTRY * pCur
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
__drv_raisesIRQL(DISPATCH_LEVEL) __drv_maxIRQL(DISPATCH_LEVEL) VOID FxSpinLock
Definition: fxspinlock.cpp:53
FX_SPIN_LOCK_HISTORY_ENTRY History[FX_SPIN_LOCK_NUM_HISTORY_ENTRIES]
Definition: fxspinlock.hpp:36
#define TRACINGERROR
Definition: dbgtrace.h:63
#define __in
Definition: dbghelp.h:35