From bbb5fb7e250d31538554d111753f3698782cc796 Mon Sep 17 00:00:00 2001 From: Zhiyi Zhang Date: Fri, 12 Aug 2022 11:32:54 +0800 Subject: [PATCH] uxtheme: Use atomic functions for reference counting. Signed-off-by: Zhiyi Zhang --- dlls/uxtheme/msstyles.c | 13 ++++++++----- dlls/uxtheme/msstyles.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/dlls/uxtheme/msstyles.c b/dlls/uxtheme/msstyles.c index 529a280b2e5..cfd21a48989 100644 --- a/dlls/uxtheme/msstyles.c +++ b/dlls/uxtheme/msstyles.c @@ -171,7 +171,7 @@ HRESULT MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile, LPCWSTR pszColorName, LPCWST (*tf)->pszAvailSizes = pszSizes; (*tf)->pszSelectedColor = pszSelectedColor; (*tf)->pszSelectedSize = pszSelectedSize; - (*tf)->dwRefCount = 1; + (*tf)->refcount = 1; return S_OK; invalid_theme: @@ -187,9 +187,12 @@ invalid_theme: */ void MSSTYLES_CloseThemeFile(PTHEME_FILE tf) { + LONG refcount; + if(tf) { - tf->dwRefCount--; - if(!tf->dwRefCount) { + refcount = InterlockedDecrement(&tf->refcount); + if (!refcount) + { if(tf->hTheme) FreeLibrary(tf->hTheme); if(tf->classes) { while(tf->classes) { @@ -235,7 +238,7 @@ HRESULT MSSTYLES_SetActiveTheme(PTHEME_FILE tf, BOOL setMetrics) tfActiveTheme = tf; if (tfActiveTheme) { - tfActiveTheme->dwRefCount++; + InterlockedIncrement(&tfActiveTheme->refcount); if(!tfActiveTheme->classes) MSSTYLES_ParseThemeIni(tfActiveTheme, setMetrics); } @@ -1061,7 +1064,7 @@ PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList, U if(cls) { TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName), debugstr_w(pszClassList)); cls->tf = tfActiveTheme; - cls->tf->dwRefCount++; + InterlockedIncrement(&cls->tf->refcount); InterlockedIncrement(&cls->refcount); cls->dpi = dpi; } diff --git a/dlls/uxtheme/msstyles.h b/dlls/uxtheme/msstyles.h index 9fe99784838..98e1aa045d6 100644 --- a/dlls/uxtheme/msstyles.h +++ b/dlls/uxtheme/msstyles.h @@ -71,7 +71,7 @@ typedef struct _THEME_IMAGE { } THEME_IMAGE, *PTHEME_IMAGE; typedef struct _THEME_FILE { - DWORD dwRefCount; + LONG refcount; HMODULE hTheme; WCHAR szThemeFile[MAX_PATH]; LPWSTR pszAvailColors;