https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6e97b4314f9550f771f38…
commit 6e97b4314f9550f771f38f3959b25bc5ef171bbb
Author: Victor Perevertkin <victor.perevertkin(a)reactos.org>
AuthorDate: Wed Feb 16 01:25:25 2022 +0300
Commit: Victor Perevertkin <victor.perevertkin(a)reactos.org>
CommitDate: Wed Feb 16 01:31:27 2022 +0300
[PORTCLS] Centralize AddRef/Release implementation.
And make it thread-safe.
Co-authored-by: Thomas Faber <thomas.faber(a)reactos.org>
---
drivers/wdm/audio/backpln/portcls/connection.cpp | 22 +----------
drivers/wdm/audio/backpln/portcls/dma_slave.cpp | 23 +-----------
drivers/wdm/audio/backpln/portcls/drm_port.cpp | 22 +----------
drivers/wdm/audio/backpln/portcls/filter_dmus.cpp | 19 +---------
.../wdm/audio/backpln/portcls/filter_topology.cpp | 19 +---------
.../audio/backpln/portcls/filter_wavecyclic.cpp | 19 +---------
.../wdm/audio/backpln/portcls/filter_wavepci.cpp | 20 +---------
.../wdm/audio/backpln/portcls/filter_wavert.cpp | 20 +---------
drivers/wdm/audio/backpln/portcls/interrupt.cpp | 20 +---------
drivers/wdm/audio/backpln/portcls/irpstream.cpp | 19 +---------
.../wdm/audio/backpln/portcls/miniport_dmus.cpp | 43 +---------------------
drivers/wdm/audio/backpln/portcls/pin_dmus.cpp | 20 +---------
.../wdm/audio/backpln/portcls/pin_wavecyclic.cpp | 24 +-----------
drivers/wdm/audio/backpln/portcls/pin_wavepci.cpp | 22 +----------
drivers/wdm/audio/backpln/portcls/pin_wavert.cpp | 20 +---------
drivers/wdm/audio/backpln/portcls/port_dmus.cpp | 21 +----------
.../wdm/audio/backpln/portcls/port_topology.cpp | 22 +----------
.../wdm/audio/backpln/portcls/port_wavecyclic.cpp | 23 +-----------
drivers/wdm/audio/backpln/portcls/port_wavepci.cpp | 23 +-----------
drivers/wdm/audio/backpln/portcls/port_wavert.cpp | 24 +-----------
.../audio/backpln/portcls/port_wavertstream.cpp | 21 +----------
drivers/wdm/audio/backpln/portcls/private.hpp | 33 +++++++++++++++++
drivers/wdm/audio/backpln/portcls/registry.cpp | 25 +++----------
drivers/wdm/audio/backpln/portcls/resource.cpp | 32 ++++++----------
.../wdm/audio/backpln/portcls/service_group.cpp | 22 +----------
drivers/wdm/audio/backpln/portcls/unregister.cpp | 25 +------------
drivers/wdm/audio/backpln/portcls/version.cpp | 24 +-----------
27 files changed, 80 insertions(+), 547 deletions(-)
diff --git a/drivers/wdm/audio/backpln/portcls/connection.cpp
b/drivers/wdm/audio/backpln/portcls/connection.cpp
index ebaa8431eba..ffa71c80137 100644
--- a/drivers/wdm/audio/backpln/portcls/connection.cpp
+++ b/drivers/wdm/audio/backpln/portcls/connection.cpp
@@ -25,36 +25,16 @@ RtlCreateUnicodeString(
);
-class CUnregisterPhysicalConnection : public IUnregisterPhysicalConnection
+class CUnregisterPhysicalConnection : public
CUnknownImpl<IUnregisterPhysicalConnection>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IUnregisterPhysicalConnection;
CUnregisterPhysicalConnection(IUnknown *OuterUnknown){}
virtual ~CUnregisterPhysicalConnection(){}
-
-protected:
- LONG m_Ref;
-
};
NTSTATUS
diff --git a/drivers/wdm/audio/backpln/portcls/dma_slave.cpp
b/drivers/wdm/audio/backpln/portcls/dma_slave.cpp
index 40d5132f6f4..ef71d248981 100644
--- a/drivers/wdm/audio/backpln/portcls/dma_slave.cpp
+++ b/drivers/wdm/audio/backpln/portcls/dma_slave.cpp
@@ -14,7 +14,7 @@
#include <debug.h>
-class CDmaChannelInit : public IDmaChannelInit
+class CDmaChannelInit : public CUnknownImpl<IDmaChannelInit>
{
public:
inline
@@ -29,22 +29,6 @@ public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IDmaChannelInit;
CDmaChannelInit(IUnknown * OuterUnknown) :
m_pDeviceObject(nullptr),
@@ -60,8 +44,7 @@ public:
m_Address({0}),
m_Buffer(nullptr),
m_Mdl(nullptr),
- m_WriteToDevice(FALSE),
- m_Ref(0)
+ m_WriteToDevice(FALSE)
{
}
virtual ~CDmaChannelInit(){}
@@ -89,8 +72,6 @@ protected:
BOOLEAN m_WriteToDevice;
friend IO_ALLOCATION_ACTION NTAPI AdapterControl(IN PDEVICE_OBJECT DeviceObject, IN
PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context);
-
- LONG m_Ref;
};
diff --git a/drivers/wdm/audio/backpln/portcls/drm_port.cpp
b/drivers/wdm/audio/backpln/portcls/drm_port.cpp
index 04f694b12b2..6d10cd8d626 100644
--- a/drivers/wdm/audio/backpln/portcls/drm_port.cpp
+++ b/drivers/wdm/audio/backpln/portcls/drm_port.cpp
@@ -14,34 +14,14 @@
#include <debug.h>
-class CDrmPort2 : public IDrmPort2
+class CDrmPort2 : public CUnknownImpl<IDrmPort2>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IDrmPort2;
CDrmPort2(IUnknown *OuterUnknown){}
virtual ~CDrmPort2(){}
-
-protected:
- LONG m_Ref;
-
};
NTSTATUS
diff --git a/drivers/wdm/audio/backpln/portcls/filter_dmus.cpp
b/drivers/wdm/audio/backpln/portcls/filter_dmus.cpp
index 3d86166c82f..b375cd8b67e 100644
--- a/drivers/wdm/audio/backpln/portcls/filter_dmus.cpp
+++ b/drivers/wdm/audio/backpln/portcls/filter_dmus.cpp
@@ -14,27 +14,11 @@
#include <debug.h>
-class CPortFilterDMus : public IPortFilterDMus
+class CPortFilterDMus : public CUnknownImpl<IPortFilterDMus>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortFilterDMus;
CPortFilterDMus(IUnknown *OuterUnknown){}
virtual ~CPortFilterDMus(){}
@@ -43,7 +27,6 @@ protected:
IPortDMus* m_Port;
IPortPinDMus ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor;
- LONG m_Ref;
};
NTSTATUS
diff --git a/drivers/wdm/audio/backpln/portcls/filter_topology.cpp
b/drivers/wdm/audio/backpln/portcls/filter_topology.cpp
index 8acf5fed4dd..150de8c3cab 100644
--- a/drivers/wdm/audio/backpln/portcls/filter_topology.cpp
+++ b/drivers/wdm/audio/backpln/portcls/filter_topology.cpp
@@ -14,27 +14,11 @@
#include <debug.h>
-class CPortFilterTopology : public IPortFilterTopology
+class CPortFilterTopology : public CUnknownImpl<IPortFilterTopology>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortFilterTopology;
CPortFilterTopology(IUnknown *OuterUnknown){}
virtual ~CPortFilterTopology(){}
@@ -43,7 +27,6 @@ protected:
IPortTopology * m_Port;
SUBDEVICE_DESCRIPTOR * m_Descriptor;
ISubdevice * m_SubDevice;
- LONG m_Ref;
};
diff --git a/drivers/wdm/audio/backpln/portcls/filter_wavecyclic.cpp
b/drivers/wdm/audio/backpln/portcls/filter_wavecyclic.cpp
index 29c9512a734..6a935da41c6 100644
--- a/drivers/wdm/audio/backpln/portcls/filter_wavecyclic.cpp
+++ b/drivers/wdm/audio/backpln/portcls/filter_wavecyclic.cpp
@@ -14,27 +14,11 @@
#include <debug.h>
-class CPortFilterWaveCyclic : public IPortFilterWaveCyclic
+class CPortFilterWaveCyclic : public CUnknownImpl<IPortFilterWaveCyclic>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortFilterWaveCyclic;
CPortFilterWaveCyclic(IUnknown *OuterUnknown){}
virtual ~CPortFilterWaveCyclic(){}
@@ -44,7 +28,6 @@ protected:
IPortPinWaveCyclic ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor;
ISubdevice * m_SubDevice;
- LONG m_Ref;
};
NTSTATUS
diff --git a/drivers/wdm/audio/backpln/portcls/filter_wavepci.cpp
b/drivers/wdm/audio/backpln/portcls/filter_wavepci.cpp
index 5c5d262956f..9bf3a9465b8 100644
--- a/drivers/wdm/audio/backpln/portcls/filter_wavepci.cpp
+++ b/drivers/wdm/audio/backpln/portcls/filter_wavepci.cpp
@@ -14,27 +14,11 @@
#include <debug.h>
-class CPortFilterWavePci : public IPortFilterWavePci
+class CPortFilterWavePci : public CUnknownImpl<IPortFilterWavePci>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortFilterPci;
CPortFilterWavePci(IUnknown *OuterUnknown){}
virtual ~CPortFilterWavePci(){}
@@ -43,8 +27,6 @@ protected:
IPortWavePci* m_Port;
IPortPinWavePci ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor;
-
- LONG m_Ref;
};
NTSTATUS
diff --git a/drivers/wdm/audio/backpln/portcls/filter_wavert.cpp
b/drivers/wdm/audio/backpln/portcls/filter_wavert.cpp
index f421c2876e3..a91abafb880 100644
--- a/drivers/wdm/audio/backpln/portcls/filter_wavert.cpp
+++ b/drivers/wdm/audio/backpln/portcls/filter_wavert.cpp
@@ -14,38 +14,20 @@
#include <debug.h>
-class CPortFilterWaveRT : public IPortFilterWaveRT
+class CPortFilterWaveRT : public CUnknownImpl<IPortFilterWaveRT>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortFilterWaveRT;
CPortFilterWaveRT(IUnknown *OuterUnknown){}
virtual ~CPortFilterWaveRT(){}
protected:
-
IPortWaveRT* m_Port;
IPortPinWaveRT ** m_Pins;
SUBDEVICE_DESCRIPTOR * m_Descriptor;
- LONG m_Ref;
};
NTSTATUS
diff --git a/drivers/wdm/audio/backpln/portcls/interrupt.cpp
b/drivers/wdm/audio/backpln/portcls/interrupt.cpp
index 05f66253baf..f733c615974 100644
--- a/drivers/wdm/audio/backpln/portcls/interrupt.cpp
+++ b/drivers/wdm/audio/backpln/portcls/interrupt.cpp
@@ -21,27 +21,11 @@ typedef struct
PVOID DynamicContext;
}SYNC_ENTRY, *PSYNC_ENTRY;
-class CInterruptSync : public IInterruptSync
+class CInterruptSync : public CUnknownImpl<IInterruptSync>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IInterruptSync;
CInterruptSync(IUnknown *OuterUnknown){}
virtual ~CInterruptSync(){}
@@ -59,8 +43,6 @@ public:
PVOID m_DynamicContext;
NTSTATUS m_Status;
- LONG m_Ref;
-
friend BOOLEAN NTAPI CInterruptSynchronizedRoutine(IN PVOID ServiceContext);
friend BOOLEAN NTAPI IInterruptServiceRoutine(IN PKINTERRUPT Interrupt, IN PVOID
ServiceContext);
};
diff --git a/drivers/wdm/audio/backpln/portcls/irpstream.cpp
b/drivers/wdm/audio/backpln/portcls/irpstream.cpp
index 75f0717ec88..4e2b701eca1 100644
--- a/drivers/wdm/audio/backpln/portcls/irpstream.cpp
+++ b/drivers/wdm/audio/backpln/portcls/irpstream.cpp
@@ -39,27 +39,11 @@ RemoveHeadList_IRP(
/* no non canceled irp has been found */
return NULL;
}
-class CIrpQueue : public IIrpQueue
+class CIrpQueue : public CUnknownImpl<IIrpQueue>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IIrpQueue;
CIrpQueue(IUnknown *OuterUnknown){}
virtual ~CIrpQueue(){}
@@ -83,7 +67,6 @@ protected:
ULONG m_CurrentOffset;
PIRP m_Irp;
- volatile LONG m_Ref;
};
typedef struct
diff --git a/drivers/wdm/audio/backpln/portcls/miniport_dmus.cpp
b/drivers/wdm/audio/backpln/portcls/miniport_dmus.cpp
index 1f28043738b..f57aa72a7dc 100644
--- a/drivers/wdm/audio/backpln/portcls/miniport_dmus.cpp
+++ b/drivers/wdm/audio/backpln/portcls/miniport_dmus.cpp
@@ -66,13 +66,9 @@ const ULONG kMPUInputBufferSize = 128;
* so it can expose this interface and CUnknown so it automatically gets
* reference counting and aggregation support.
*/
-class CMiniportDMusUART
-: public IMiniportDMus,
- public IMusicTechnology,
- public IPowerNotify
+class CMiniportDMusUART : public CUnknownImpl<IMiniportDMus, IMusicTechnology,
IPowerNotify>
{
private:
- LONG m_Ref; // Reference count
KSSTATE m_KSStateInput; // Miniport state (RUN/PAUSE/ACQUIRE/STOP)
PPORTDMUS m_pPort; // Callback interface.
PUCHAR m_pPortBase; // Base port address.
@@ -105,23 +101,6 @@ private:
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
-
CMiniportDMusUART(IUnknown * Unknown){}
virtual ~CMiniportDMusUART();
@@ -204,10 +183,9 @@ public:
* so it can expose this interface and CUnknown so it automatically gets
* reference counting and aggregation support.
*/
-class CMiniportDMusUARTStream : public IMXF
+class CMiniportDMusUARTStream : public CUnknownImpl<IMXF>
{
private:
- LONG m_Ref; // Reference Count
CMiniportDMusUART * m_pMiniport; // Parent.
REFERENCE_TIME m_SnapshotTimeStamp; // Current snapshot of miniport's
input timestamp.
PUCHAR m_pPortBase; // Base port address.
@@ -230,23 +208,6 @@ private:
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
-
virtual ~CMiniportDMusUARTStream();
STDMETHODIMP_(NTSTATUS) Init
diff --git a/drivers/wdm/audio/backpln/portcls/pin_dmus.cpp
b/drivers/wdm/audio/backpln/portcls/pin_dmus.cpp
index 106ca82a48d..ef07aabed7d 100644
--- a/drivers/wdm/audio/backpln/portcls/pin_dmus.cpp
+++ b/drivers/wdm/audio/backpln/portcls/pin_dmus.cpp
@@ -14,27 +14,11 @@
#include <debug.h>
-class CPortPinDMus : public IPortPinDMus
+class CPortPinDMus : public CUnknownImpl<IPortPinDMus>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortPinDMus;
IMP_IServiceSink;
IMP_IMasterClock;
@@ -76,8 +60,6 @@ protected:
ULONG m_PostCompleted;
ULONG m_LastTag;
-
- LONG m_Ref;
};
typedef struct
diff --git a/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.cpp
b/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.cpp
index 07451f6190a..ec67bb50ef0 100644
--- a/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.cpp
+++ b/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.cpp
@@ -14,8 +14,7 @@
#include <debug.h>
-class CPortPinWaveCyclic : public IPortPinWaveCyclic,
- public IServiceSink
+class CPortPinWaveCyclic : public CUnknownImpl<IPortPinWaveCyclic, IServiceSink>
{
public:
inline
@@ -30,22 +29,6 @@ public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortPinWaveCyclic;
IMP_IServiceSink;
CPortPinWaveCyclic(IUnknown *OuterUnknown) :
@@ -73,8 +56,7 @@ public:
m_EventListLock(0),
m_EventList({nullptr}),
m_ResetState(KSRESET_BEGIN),
- m_Delay(0),
- m_Ref(0)
+ m_Delay(0)
{
}
virtual ~CPortPinWaveCyclic(){}
@@ -125,8 +107,6 @@ protected:
KSRESET m_ResetState;
ULONG m_Delay;
-
- LONG m_Ref;
};
diff --git a/drivers/wdm/audio/backpln/portcls/pin_wavepci.cpp
b/drivers/wdm/audio/backpln/portcls/pin_wavepci.cpp
index 9f681a000c2..879965edc32 100644
--- a/drivers/wdm/audio/backpln/portcls/pin_wavepci.cpp
+++ b/drivers/wdm/audio/backpln/portcls/pin_wavepci.cpp
@@ -14,29 +14,11 @@
#include <debug.h>
-class CPortPinWavePci : public IPortPinWavePci,
- public IServiceSink,
- public IPortWavePciStream
+class CPortPinWavePci : public CUnknownImpl<IPortPinWavePci, IServiceSink,
IPortWavePciStream>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortPinWavePci;
IMP_IServiceSink;
IMP_IPortWavePciStream;
@@ -74,8 +56,6 @@ protected:
KSALLOCATOR_FRAMING m_AllocatorFraming;
- LONG m_Ref;
-
NTSTATUS NTAPI HandleKsProperty(IN PIRP Irp);
NTSTATUS NTAPI HandleKsStream(IN PIRP Irp);
};
diff --git a/drivers/wdm/audio/backpln/portcls/pin_wavert.cpp
b/drivers/wdm/audio/backpln/portcls/pin_wavert.cpp
index fcdfd1ce812..d259649d3c0 100644
--- a/drivers/wdm/audio/backpln/portcls/pin_wavert.cpp
+++ b/drivers/wdm/audio/backpln/portcls/pin_wavert.cpp
@@ -14,27 +14,11 @@
#include <debug.h>
-class CPortPinWaveRT : public IPortPinWaveRT
+class CPortPinWaveRT : public CUnknownImpl<IPortPinWaveRT>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortPinWaveRT;
CPortPinWaveRT(IUnknown *OuterUnknown){}
virtual ~CPortPinWaveRT(){}
@@ -68,8 +52,6 @@ protected:
MEMORY_CACHING_TYPE m_CacheType;
PMDL m_Mdl;
- LONG m_Ref;
-
NTSTATUS NTAPI HandleKsProperty(IN PIRP Irp);
NTSTATUS NTAPI HandleKsStream(IN PIRP Irp);
VOID NTAPI SetStreamState(IN KSSTATE State);
diff --git a/drivers/wdm/audio/backpln/portcls/port_dmus.cpp
b/drivers/wdm/audio/backpln/portcls/port_dmus.cpp
index 7eb94d2d6ec..8a3e8cdae13 100644
--- a/drivers/wdm/audio/backpln/portcls/port_dmus.cpp
+++ b/drivers/wdm/audio/backpln/portcls/port_dmus.cpp
@@ -14,28 +14,11 @@
#include <debug.h>
-class CPortDMus : public IPortDMus,
- public ISubdevice
+class CPortDMus : public CUnknownImpl<IPortDMus, ISubdevice>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortDMus;
IMP_ISubdevice;
CPortDMus(IUnknown *OuterUnknown){}
@@ -55,8 +38,6 @@ protected:
PPCFILTER_DESCRIPTOR m_pDescriptor;
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor;
- LONG m_Ref;
-
friend VOID GetDMusMiniport(IN IPortDMus * iface, IN PMINIPORTDMUS * Miniport, IN
PMINIPORTMIDI * MidiMiniport);
};
diff --git a/drivers/wdm/audio/backpln/portcls/port_topology.cpp
b/drivers/wdm/audio/backpln/portcls/port_topology.cpp
index 2c5cf4333fa..32467b3d6a4 100644
--- a/drivers/wdm/audio/backpln/portcls/port_topology.cpp
+++ b/drivers/wdm/audio/backpln/portcls/port_topology.cpp
@@ -14,29 +14,11 @@
#include <debug.h>
-class CPortTopology : public IPortTopology,
- public ISubdevice,
- public IPortEvents
+class CPortTopology : public CUnknownImpl<IPortTopology, ISubdevice, IPortEvents>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortTopology;
IMP_ISubdevice;
IMP_IPortEvents;
@@ -55,8 +37,6 @@ protected:
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor;
IPortFilterTopology * m_Filter;
- LONG m_Ref;
-
friend PMINIPORTTOPOLOGY GetTopologyMiniport(PPORTTOPOLOGY Port);
};
diff --git a/drivers/wdm/audio/backpln/portcls/port_wavecyclic.cpp
b/drivers/wdm/audio/backpln/portcls/port_wavecyclic.cpp
index cb54dcc275b..3a4f3545de7 100644
--- a/drivers/wdm/audio/backpln/portcls/port_wavecyclic.cpp
+++ b/drivers/wdm/audio/backpln/portcls/port_wavecyclic.cpp
@@ -16,32 +16,15 @@
GUID IID_IDmaChannelSlave;
-class CPortWaveCyclic : public IPortWaveCyclic,
- public IPortEvents,
- public ISubdevice
+class CPortWaveCyclic : public CUnknownImpl<IPortWaveCyclic, IPortEvents,
ISubdevice>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortWaveCyclic;
IMP_ISubdevice;
IMP_IPortEvents;
- CPortWaveCyclic(IUnknown *OuterUnknown) : m_Ref(0) {}
+ CPortWaveCyclic(IUnknown *OuterUnknown) {}
virtual ~CPortWaveCyclic(){}
protected:
@@ -53,8 +36,6 @@ protected:
PSUBDEVICE_DESCRIPTOR m_SubDeviceDescriptor;
IPortFilterWaveCyclic * m_Filter;
- LONG m_Ref;
-
friend PMINIPORTWAVECYCLIC GetWaveCyclicMiniport(IN IPortWaveCyclic* iface);
friend PDEVICE_OBJECT GetDeviceObject(PPORTWAVECYCLIC iface);
};
diff --git a/drivers/wdm/audio/backpln/portcls/port_wavepci.cpp
b/drivers/wdm/audio/backpln/portcls/port_wavepci.cpp
index 0186258c328..068d28256a8 100644
--- a/drivers/wdm/audio/backpln/portcls/port_wavepci.cpp
+++ b/drivers/wdm/audio/backpln/portcls/port_wavepci.cpp
@@ -14,30 +14,11 @@
#include <debug.h>
-class CPortWavePci : public IPortWavePci,
- public IPortEvents,
- public ISubdevice,
- public IServiceSink
+class CPortWavePci : public CUnknownImpl<IPortWavePci, IPortEvents, ISubdevice,
IServiceSink>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortWavePci;
IMP_ISubdevice;
IMP_IPortEvents;
@@ -59,8 +40,6 @@ protected:
LIST_ENTRY m_EventList;
KSPIN_LOCK m_EventListLock;
- LONG m_Ref;
-
friend PDEVICE_OBJECT GetDeviceObjectFromPortWavePci(IPortWavePci* iface);
friend PMINIPORTWAVEPCI GetWavePciMiniport(PPORTWAVEPCI iface);
diff --git a/drivers/wdm/audio/backpln/portcls/port_wavert.cpp
b/drivers/wdm/audio/backpln/portcls/port_wavert.cpp
index 06e97c95b9c..c7f5f7d51ab 100644
--- a/drivers/wdm/audio/backpln/portcls/port_wavert.cpp
+++ b/drivers/wdm/audio/backpln/portcls/port_wavert.cpp
@@ -14,29 +14,11 @@
#include <debug.h>
-class CPortWaveRT : public IPortWaveRT,
- public IPortEvents,
- public ISubdevice
+class CPortWaveRT : public CUnknownImpl<IPortWaveRT, IPortEvents, ISubdevice>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortWaveRT;
IMP_ISubdevice;
IMP_IPortEvents;
@@ -57,8 +39,6 @@ protected:
friend PMINIPORTWAVERT GetWaveRTMiniport(IN IPortWaveRT* iface);
friend PDEVICE_OBJECT GetDeviceObjectFromPortWaveRT(PPORTWAVERT iface);
-
- LONG m_Ref;
};
static GUID InterfaceGuids[3] =
@@ -145,7 +125,7 @@ CPortWaveRT::QueryInterface(
IsEqualGUIDAligned(refiid, IID_IUnknown))
{
*Output = PVOID(PPORTWAVERT(this));
- PUNKNOWN(*Output)->AddRef();
+ PUNKNOWN(*Output)->AddRef();
return STATUS_SUCCESS;
}
else if (IsEqualGUIDAligned(refiid, IID_IPortEvents))
diff --git a/drivers/wdm/audio/backpln/portcls/port_wavertstream.cpp
b/drivers/wdm/audio/backpln/portcls/port_wavertstream.cpp
index 3472c071f66..4689f07b609 100644
--- a/drivers/wdm/audio/backpln/portcls/port_wavertstream.cpp
+++ b/drivers/wdm/audio/backpln/portcls/port_wavertstream.cpp
@@ -14,34 +14,15 @@
#include <debug.h>
-class CPortWaveRTStreamInit : public IPortWaveRTStreamInit
+class CPortWaveRTStreamInit : public CUnknownImpl<IPortWaveRTStreamInit>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
IMP_IPortWaveRTStreamInit;
CPortWaveRTStreamInit(IUnknown *OuterUnknown) {}
virtual ~CPortWaveRTStreamInit() {}
-protected:
- LONG m_Ref;
-
};
NTSTATUS
diff --git a/drivers/wdm/audio/backpln/portcls/private.hpp
b/drivers/wdm/audio/backpln/portcls/private.hpp
index 75549690577..f17d0788505 100644
--- a/drivers/wdm/audio/backpln/portcls/private.hpp
+++ b/drivers/wdm/audio/backpln/portcls/private.hpp
@@ -439,4 +439,37 @@ typedef struct
PKSOBJECT_CREATE_ITEM CreateItem;
}DISPATCH_CONTEXT, *PDISPATCH_CONTEXT;
+template<typename... Interfaces>
+class CUnknownImpl : public Interfaces...
+{
+private:
+ volatile LONG m_Ref;
+protected:
+ CUnknownImpl() :
+ m_Ref(0)
+ {
+ }
+ virtual ~CUnknownImpl()
+ {
+ }
+public:
+ STDMETHODIMP_(ULONG) AddRef()
+ {
+ ULONG Ref = InterlockedIncrement(&m_Ref);
+ ASSERT(Ref < 0x10000);
+ return Ref;
+ }
+ STDMETHODIMP_(ULONG) Release()
+ {
+ ULONG Ref = InterlockedDecrement(&m_Ref);
+ ASSERT(Ref < 0x10000);
+ if (!Ref)
+ {
+ delete this;
+ return 0;
+ }
+ return Ref;
+ }
+};
+
#endif /* PORTCLS_PRIVATE_H */
diff --git a/drivers/wdm/audio/backpln/portcls/registry.cpp
b/drivers/wdm/audio/backpln/portcls/registry.cpp
index 35b7946d384..56a8cc144c8 100644
--- a/drivers/wdm/audio/backpln/portcls/registry.cpp
+++ b/drivers/wdm/audio/backpln/portcls/registry.cpp
@@ -14,30 +14,18 @@
#include <debug.h>
-class CRegistryKey : public IRegistryKey
+class CRegistryKey : public CUnknownImpl<IRegistryKey>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
+ IMP_IRegistryKey;
+ CRegistryKey(IUnknown * OuterUnknown, HANDLE hKey, BOOL CanDelete) :
+ m_hKey(hKey),
+ m_Deleted(FALSE),
+ m_CanDelete(CanDelete)
{
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
}
-
- IMP_IRegistryKey;
- CRegistryKey(IUnknown * OuterUnknown, HANDLE hKey, BOOL CanDelete) : m_hKey(hKey),
m_Deleted(FALSE), m_CanDelete(CanDelete), m_Ref(0){}
virtual ~CRegistryKey();
protected:
@@ -45,7 +33,6 @@ protected:
HANDLE m_hKey;
BOOL m_Deleted;
BOOL m_CanDelete;
- LONG m_Ref;
};
CRegistryKey::~CRegistryKey()
diff --git a/drivers/wdm/audio/backpln/portcls/resource.cpp
b/drivers/wdm/audio/backpln/portcls/resource.cpp
index dfa4e7b7d83..19020345579 100644
--- a/drivers/wdm/audio/backpln/portcls/resource.cpp
+++ b/drivers/wdm/audio/backpln/portcls/resource.cpp
@@ -17,31 +17,22 @@
#include <debug.h>
-class CResourceList : public IResourceList
+class CResourceList : public CUnknownImpl<IResourceList>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
-
IMP_IResourceList;
- CResourceList(IUnknown * OuterUnknown) : m_OuterUnknown(OuterUnknown),
m_PoolType(NonPagedPool), m_TranslatedResourceList(0), m_UntranslatedResourceList(0),
m_NumberOfEntries(0), m_MaxEntries(0), m_Ref(0) {}
+ CResourceList(IUnknown * OuterUnknown) :
+ m_OuterUnknown(OuterUnknown),
+ m_PoolType(NonPagedPool),
+ m_TranslatedResourceList(0),
+ m_UntranslatedResourceList(0),
+ m_NumberOfEntries(0),
+ m_MaxEntries(0)
+ {
+ }
virtual ~CResourceList();
public:
@@ -51,7 +42,6 @@ public:
PCM_RESOURCE_LIST m_UntranslatedResourceList;
ULONG m_NumberOfEntries;
ULONG m_MaxEntries;
- LONG m_Ref;
};
CResourceList::~CResourceList()
@@ -461,7 +451,7 @@ PcNewResourceSublist(
/* Store members */
NewList->m_OuterUnknown = OuterUnknown;
NewList->m_PoolType = PoolType;
- NewList->m_Ref = 1;
+ NewList->AddRef();
NewList->m_NumberOfEntries = 0;
NewList->m_MaxEntries = MaximumEntries;
diff --git a/drivers/wdm/audio/backpln/portcls/service_group.cpp
b/drivers/wdm/audio/backpln/portcls/service_group.cpp
index 50ebd7335a4..d3688a92c14 100644
--- a/drivers/wdm/audio/backpln/portcls/service_group.cpp
+++ b/drivers/wdm/audio/backpln/portcls/service_group.cpp
@@ -29,28 +29,11 @@ typedef struct
IN PSERVICESINK pServiceSink;
}GROUP_ENTRY, *PGROUP_ENTRY;
-class CServiceGroup : public IServiceGroup
+class CServiceGroup : public CUnknownImpl<IServiceGroup>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
-
IMP_IServiceGroup;
CServiceGroup(IUnknown * OuterUnknown);
virtual ~CServiceGroup() {}
@@ -65,9 +48,6 @@ protected:
KSPIN_LOCK m_Lock;
friend VOID NTAPI IServiceGroupDpc(IN struct _KDPC *Dpc, IN PVOID DeferredContext,
IN PVOID SystemArgument1, IN PVOID SystemArgument2);
-
- LONG m_Ref;
-
};
diff --git a/drivers/wdm/audio/backpln/portcls/unregister.cpp
b/drivers/wdm/audio/backpln/portcls/unregister.cpp
index 9a3bc8cec66..ef9d7130888 100644
--- a/drivers/wdm/audio/backpln/portcls/unregister.cpp
+++ b/drivers/wdm/audio/backpln/portcls/unregister.cpp
@@ -14,37 +14,16 @@
#include <debug.h>
-class CUnregisterSubdevice : public IUnregisterSubdevice
+class CUnregisterSubdevice : public CUnknownImpl<IUnregisterSubdevice>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
-
-
IMP_IUnregisterSubdevice;
- CUnregisterSubdevice(IUnknown * OuterUnknown) : m_Ref(0) {}
+ CUnregisterSubdevice(IUnknown * OuterUnknown) {}
virtual ~CUnregisterSubdevice(){}
-protected:
- LONG m_Ref;
-
};
NTSTATUS
diff --git a/drivers/wdm/audio/backpln/portcls/version.cpp
b/drivers/wdm/audio/backpln/portcls/version.cpp
index 629c74a4a6a..c3571cc7bd1 100644
--- a/drivers/wdm/audio/backpln/portcls/version.cpp
+++ b/drivers/wdm/audio/backpln/portcls/version.cpp
@@ -14,42 +14,20 @@
#include <debug.h>
-class CPortClsVersion : public IPortClsVersion
+class CPortClsVersion : public CUnknownImpl<IPortClsVersion>
{
public:
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
- STDMETHODIMP_(ULONG) AddRef()
- {
- InterlockedIncrement(&m_Ref);
- return m_Ref;
- }
- STDMETHODIMP_(ULONG) Release()
- {
- InterlockedDecrement(&m_Ref);
-
- if (!m_Ref)
- {
- delete this;
- return 0;
- }
- return m_Ref;
- }
-
IMP_IPortClsVersion;
CPortClsVersion(IUnknown *OuterUnknown)
{
- m_Ref = 0;
}
virtual ~CPortClsVersion()
{
}
-
-protected:
- LONG m_Ref;
-
};