Module: wine Branch: master Commit: 744f94be4abcbf65627d45b57746a80c8e6799e8 URL: http://source.winehq.org/git/wine.git/?a=commit;h=744f94be4abcbf65627d45b577...
Author: Michael Stefaniuc mstefani@redhat.de Date: Wed Sep 4 23:50:58 2013 +0200
dplayx: Simplify ref-counting for IDirectPlaySP.
---
dlls/dplayx/dplaysp.c | 71 +++++++++++++----------------------------------- 1 files changed, 19 insertions(+), 52 deletions(-)
diff --git a/dlls/dplayx/dplaysp.c b/dlls/dplayx/dplaysp.c index aac2811..52fe09f 100644 --- a/dlls/dplayx/dplaysp.c +++ b/dlls/dplayx/dplaysp.c @@ -44,7 +44,6 @@ typedef struct IDirectPlaySPImpl IDirectPlaySPImpl;
typedef struct tagDirectPlaySPIUnknownData { - LONG ulObjRef; CRITICAL_SECTION DPSP_lock; } DirectPlaySPIUnknownData;
@@ -61,13 +60,13 @@ typedef struct tagDirectPlaySPData } DirectPlaySPData;
#define DPSP_IMPL_FIELDS \ - LONG ulInterfaceRef; \ DirectPlaySPIUnknownData* unk; \ DirectPlaySPData* sp;
struct IDirectPlaySPImpl { const IDirectPlaySPVtbl *lpVtbl; + LONG ref; DPSP_IMPL_FIELDS };
@@ -194,79 +193,47 @@ static inline IDirectPlaySPImpl *impl_from_IDirectPlaySP( IDirectPlaySP *iface ) }
static HRESULT WINAPI IDirectPlaySPImpl_QueryInterface( IDirectPlaySP *iface, REFIID riid, - void **ppvObj ) + void **ppv ) { - IDirectPlaySPImpl *This = (IDirectPlaySPImpl *)iface; - TRACE("(%p)->(%s,%p)\n", This, debugstr_guid( riid ), ppvObj ); + TRACE("(%p)->(%s,%p)\n", iface, debugstr_guid( riid ), ppv );
- *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, - sizeof( *This ) ); - - if( *ppvObj == NULL ) - { - return DPERR_OUTOFMEMORY; - } - - CopyMemory( *ppvObj, This, sizeof( *This ) ); - (*(IDirectPlaySPImpl**)ppvObj)->ulInterfaceRef = 0; - - if( IsEqualGUID( &IID_IDirectPlaySP, riid ) ) - { - IDirectPlaySPImpl *This = *ppvObj; - This->lpVtbl = &directPlaySPVT; - } - else + if ( IsEqualGUID( &IID_IUnknown, riid ) || IsEqualGUID( &IID_IDirectPlaySP, riid ) ) { - /* Unsupported interface */ - HeapFree( GetProcessHeap(), 0, *ppvObj ); - *ppvObj = NULL; - - return E_NOINTERFACE; + *ppv = iface; + IDirectPlaySP_AddRef( iface ); + return S_OK; }
- IDirectPlaySP_AddRef( (LPDIRECTPLAYSP)*ppvObj ); - - return S_OK; + FIXME( "Unsupported interface %s\n", debugstr_guid( riid ) ); + *ppv = NULL; + return E_NOINTERFACE; }
static ULONG WINAPI IDirectPlaySPImpl_AddRef( IDirectPlaySP *iface ) { IDirectPlaySPImpl *This = impl_from_IDirectPlaySP( iface ); - ULONG ulInterfaceRefCount, ulObjRefCount; - - ulObjRefCount = InterlockedIncrement( &This->unk->ulObjRef ); - ulInterfaceRefCount = InterlockedIncrement( &This->ulInterfaceRef ); + ULONG ref = InterlockedIncrement( &This->ref );
- TRACE( "ref count incremented to %u:%u for %p\n", - ulInterfaceRefCount, ulObjRefCount, This ); + TRACE( "(%p) ref=%d\n", This, ref );
- return ulObjRefCount; + return ref; }
static ULONG WINAPI IDirectPlaySPImpl_Release( IDirectPlaySP *iface ) { IDirectPlaySPImpl *This = impl_from_IDirectPlaySP( iface ); - ULONG ulInterfaceRefCount, ulObjRefCount; - - ulObjRefCount = InterlockedDecrement( &This->unk->ulObjRef ); - ulInterfaceRefCount = InterlockedDecrement( &This->ulInterfaceRef ); + ULONG ref = InterlockedDecrement( &This->ref );
- TRACE( "ref count decremented to %u:%u for %p\n", - ulInterfaceRefCount, ulObjRefCount, This ); - - /* Deallocate if this is the last reference to the object */ - if( ulObjRefCount == 0 ) - { - DPSP_DestroyDirectPlaySP( This ); - DPSP_DestroyIUnknown( This ); - } + TRACE( "(%p) ref=%d\n", This, ref );
- if( ulInterfaceRefCount == 0 ) + if( !ref ) { + DPSP_DestroyDirectPlaySP( This ); + DPSP_DestroyIUnknown( This ); HeapFree( GetProcessHeap(), 0, This ); }
- return ulInterfaceRefCount; + return ref; }
static HRESULT WINAPI IDirectPlaySPImpl_AddMRUEntry( IDirectPlaySP *iface, LPCWSTR lpSection,