Module: wine Branch: master Commit: b11dddf7cafb75902cc705d9a82e92a2b2f28ac5 URL: http://source.winehq.org/git/wine.git/?a=commit;h=b11dddf7cafb75902cc705d9a8...
Author: Michael Stefaniuc mstefani@redhat.de Date: Tue Sep 3 23:20:21 2013 +0200
dplayx: Simplify ref-counting for IDPLobbySP.
---
dlls/dplayx/lobbysp.c | 71 +++++++++++++----------------------------------- 1 files changed, 19 insertions(+), 52 deletions(-)
diff --git a/dlls/dplayx/lobbysp.c b/dlls/dplayx/lobbysp.c index 33101fd..4dd7eb2 100644 --- a/dlls/dplayx/lobbysp.c +++ b/dlls/dplayx/lobbysp.c @@ -38,7 +38,6 @@ typedef struct IDPLobbySPImpl IDPLobbySPImpl;
typedef struct tagDPLobbySPIUnknownData { - LONG ulObjRef; CRITICAL_SECTION DPLSP_lock; } DPLobbySPIUnknownData;
@@ -48,13 +47,13 @@ typedef struct tagDPLobbySPData } DPLobbySPData;
#define DPLSP_IMPL_FIELDS \ - LONG ulInterfaceRef; \ DPLobbySPIUnknownData* unk; \ DPLobbySPData* sp;
struct IDPLobbySPImpl { const IDPLobbySPVtbl *lpVtbl; + LONG ref; DPLSP_IMPL_FIELDS };
@@ -165,79 +164,47 @@ static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP ) }
static HRESULT WINAPI IDPLobbySPImpl_QueryInterface( IDPLobbySP *iface, REFIID riid, - void **ppvObj ) + void **ppv ) { - IDPLobbySPImpl *This = (IDPLobbySPImpl *)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 ) ); - (*(IDPLobbySPImpl**)ppvObj)->ulInterfaceRef = 0; - - if( IsEqualGUID( &IID_IDPLobbySP, riid ) ) - { - IDPLobbySPImpl *This = *ppvObj; - This->lpVtbl = &dpLobbySPVT; - } - else + if ( IsEqualGUID( &IID_IUnknown, riid ) || IsEqualGUID( &IID_IDPLobbySP, riid ) ) { - /* Unsupported interface */ - HeapFree( GetProcessHeap(), 0, *ppvObj ); - *ppvObj = NULL; - - return E_NOINTERFACE; + *ppv = iface; + IDPLobbySP_AddRef(iface); + return S_OK; }
- IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj ); - - return S_OK; + FIXME("Unsupported interface %s\n", debugstr_guid(riid)); + *ppv = NULL; + return E_NOINTERFACE; }
static ULONG WINAPI IDPLobbySPImpl_AddRef( IDPLobbySP *iface ) { IDPLobbySPImpl *This = impl_from_IDPLobbySP( 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 IDPLobbySPImpl_Release( IDPLobbySP *iface ) { IDPLobbySPImpl *This = impl_from_IDPLobbySP( 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 ) - { - DPLSP_DestroyDPLobbySP( This ); - DPLSP_DestroyIUnknown( This ); - } + TRACE( "(%p) ref=%d\n", This, ref );
- if( ulInterfaceRefCount == 0 ) + if( !ref ) { + DPLSP_DestroyDPLobbySP( This ); + DPLSP_DestroyIUnknown( This ); HeapFree( GetProcessHeap(), 0, This ); }
- return ulInterfaceRefCount; + return ref; }
static HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup( IDPLobbySP *iface,