From 7de4af5666ab581841b3c166ec5f8377e50c4c43 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Fri, 19 Mar 2010 13:17:29 -0500 Subject: [PATCH] windowscodecs: Make the IWICPalette implementation thread-safe. --- dlls/windowscodecs/palette.c | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) diff --git a/dlls/windowscodecs/palette.c b/dlls/windowscodecs/palette.c index 842d3b5..40ab190 100644 --- a/dlls/windowscodecs/palette.c +++ b/dlls/windowscodecs/palette.c @@ -40,6 +40,7 @@ typedef struct { UINT count; WICColor *colors; WICBitmapPaletteType type; + CRITICAL_SECTION lock; /* must be held when count, colors, or type is accessed */ } PaletteImpl; static HRESULT WINAPI PaletteImpl_QueryInterface(IWICPalette *iface, REFIID iid, @@ -83,6 +84,8 @@ static ULONG WINAPI PaletteImpl_Release(IWICPalette *iface) if (ref == 0) { + This->lock.DebugInfo->Spare[0] = 0; + DeleteCriticalSection(&This->lock); HeapFree(GetProcessHeap(), 0, This->colors); HeapFree(GetProcessHeap(), 0, This); } @@ -117,10 +120,12 @@ static HRESULT WINAPI PaletteImpl_InitializeCustom(IWICPalette *iface, memcpy(new_colors, pColors, sizeof(WICColor) * colorCount); } + EnterCriticalSection(&This->lock); HeapFree(GetProcessHeap(), 0, This->colors); This->colors = new_colors; This->count = colorCount; This->type = WICBitmapPaletteTypeCustom; + LeaveCriticalSection(&This->lock); return S_OK; } @@ -148,7 +153,9 @@ static HRESULT WINAPI PaletteImpl_GetType(IWICPalette *iface, if (!pePaletteType) return E_INVALIDARG; + EnterCriticalSection(&This->lock); *pePaletteType = This->type; + LeaveCriticalSection(&This->lock); return S_OK; } @@ -161,7 +168,9 @@ static HRESULT WINAPI PaletteImpl_GetColorCount(IWICPalette *iface, UINT *pcCoun if (!pcCount) return E_INVALIDARG; + EnterCriticalSection(&This->lock); *pcCount = This->count; + LeaveCriticalSection(&This->lock); return S_OK; } @@ -175,12 +184,16 @@ static HRESULT WINAPI PaletteImpl_GetColors(IWICPalette *iface, UINT colorCount, if (!pColors || !pcActualColors) return E_INVALIDARG; + EnterCriticalSection(&This->lock); + if (This->count < colorCount) colorCount = This->count; memcpy(pColors, This->colors, sizeof(WICColor) * colorCount); *pcActualColors = colorCount; + LeaveCriticalSection(&This->lock); + return S_OK; } @@ -192,10 +205,12 @@ static HRESULT WINAPI PaletteImpl_IsBlackWhite(IWICPalette *iface, BOOL *pfIsBla if (!pfIsBlackWhite) return E_INVALIDARG; + EnterCriticalSection(&This->lock); if (This->type == WICBitmapPaletteTypeFixedBW) *pfIsBlackWhite = TRUE; else *pfIsBlackWhite = FALSE; + LeaveCriticalSection(&This->lock); return S_OK; } @@ -208,6 +223,7 @@ static HRESULT WINAPI PaletteImpl_IsGrayscale(IWICPalette *iface, BOOL *pfIsGray if (!pfIsGrayscale) return E_INVALIDARG; + EnterCriticalSection(&This->lock); switch(This->type) { case WICBitmapPaletteTypeFixedBW: @@ -219,6 +235,7 @@ static HRESULT WINAPI PaletteImpl_IsGrayscale(IWICPalette *iface, BOOL *pfIsGray default: *pfIsGrayscale = FALSE; } + LeaveCriticalSection(&This->lock); return S_OK; } @@ -234,12 +251,14 @@ static HRESULT WINAPI PaletteImpl_HasAlpha(IWICPalette *iface, BOOL *pfHasAlpha) *pfHasAlpha = FALSE; + EnterCriticalSection(&This->lock); for (i=0; icount; i++) if ((This->colors[i]&0xff000000) != 0xff000000) { *pfHasAlpha = TRUE; break; } + LeaveCriticalSection(&This->lock); return S_OK; } @@ -272,6 +291,8 @@ HRESULT PaletteImpl_Create(IWICPalette **palette) This->count = 0; This->colors = NULL; This->type = WICBitmapPaletteTypeCustom; + InitializeCriticalSection(&This->lock); + This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": PaletteImpl.lock"); *palette = (IWICPalette*)This; -- 1.6.3.3