Merge changes Iecff615a,I1237904a into main

* changes:
  Implement WEBP_DSP_INIT with SRWLOCK for Windows
  Use file static variables in WEBP_DSP_INIT_FUNC()
This commit is contained in:
James Zern
2025-08-04 17:38:04 -07:00
committed by Gerrit Code Review

View File

@@ -189,33 +189,68 @@
#endif #endif
#endif #endif
#if defined(WEBP_USE_THREAD) && !defined(_WIN32) #if defined(WEBP_USE_THREAD)
#include <pthread.h> // NOLINT #if defined(_WIN32)
#include <windows.h>
#if _WIN32_WINNT >= 0x0600
// clang-format off // clang-format off
#define WEBP_DSP_INIT_VARS(func) \
static VP8CPUInfo func##_last_cpuinfo_used = \
(VP8CPUInfo)&func##_last_cpuinfo_used; \
static SRWLOCK func##_lock = SRWLOCK_INIT
#define WEBP_DSP_INIT(func) \ #define WEBP_DSP_INIT(func) \
do { \ do { \
AcquireSRWLockExclusive(&func##_lock); \
if (func##_last_cpuinfo_used != VP8GetCPUInfo) func(); \
func##_last_cpuinfo_used = VP8GetCPUInfo; \
ReleaseSRWLockExclusive(&func##_lock); \
} while (0)
// clang-format on
#else // _WIN32_WINNT < 0x0600
// clang-format off
#define WEBP_DSP_INIT_VARS(func) \
static volatile VP8CPUInfo func##_last_cpuinfo_used = \ static volatile VP8CPUInfo func##_last_cpuinfo_used = \
(VP8CPUInfo)&func##_last_cpuinfo_used
#define WEBP_DSP_INIT(func) \
do { \
if (func##_last_cpuinfo_used == VP8GetCPUInfo) break; \
func(); \
func##_last_cpuinfo_used = VP8GetCPUInfo; \
} while (0)
// clang-format on
#endif // _WIN32_WINNT >= 0x0600
#else // !defined(_WIN32)
// NOLINTNEXTLINE
#include <pthread.h>
// clang-format off
#define WEBP_DSP_INIT_VARS(func) \
static VP8CPUInfo func##_last_cpuinfo_used = \
(VP8CPUInfo)&func##_last_cpuinfo_used; \ (VP8CPUInfo)&func##_last_cpuinfo_used; \
static pthread_mutex_t func##_lock = PTHREAD_MUTEX_INITIALIZER; \ static pthread_mutex_t func##_lock = PTHREAD_MUTEX_INITIALIZER
#define WEBP_DSP_INIT(func) \
do { \
if (pthread_mutex_lock(&func##_lock)) break; \ if (pthread_mutex_lock(&func##_lock)) break; \
if (func##_last_cpuinfo_used != VP8GetCPUInfo) func(); \ if (func##_last_cpuinfo_used != VP8GetCPUInfo) func(); \
func##_last_cpuinfo_used = VP8GetCPUInfo; \ func##_last_cpuinfo_used = VP8GetCPUInfo; \
(void)pthread_mutex_unlock(&func##_lock); \ (void)pthread_mutex_unlock(&func##_lock); \
} while (0) } while (0)
// clang-format on // clang-format on
#else // !(defined(WEBP_USE_THREAD) && !defined(_WIN32)) #endif // defined(_WIN32)
#else // !defined(WEBP_USE_THREAD)
// clang-format off // clang-format off
#define WEBP_DSP_INIT_VARS(func) \
static volatile VP8CPUInfo func##_last_cpuinfo_used = \
(VP8CPUInfo)&func##_last_cpuinfo_used
#define WEBP_DSP_INIT(func) \ #define WEBP_DSP_INIT(func) \
do { \ do { \
static volatile VP8CPUInfo func##_last_cpuinfo_used = \
(VP8CPUInfo)&func##_last_cpuinfo_used; \
if (func##_last_cpuinfo_used == VP8GetCPUInfo) break; \ if (func##_last_cpuinfo_used == VP8GetCPUInfo) break; \
func(); \ func(); \
func##_last_cpuinfo_used = VP8GetCPUInfo; \ func##_last_cpuinfo_used = VP8GetCPUInfo; \
} while (0) } while (0)
// clang-format on // clang-format on
#endif // defined(WEBP_USE_THREAD) && !defined(_WIN32) #endif // defined(WEBP_USE_THREAD)
// Defines an Init + helper function that control multiple initialization of // Defines an Init + helper function that control multiple initialization of
// function pointers / tables. // function pointers / tables.
@@ -225,6 +260,7 @@
} }
*/ */
#define WEBP_DSP_INIT_FUNC(name) \ #define WEBP_DSP_INIT_FUNC(name) \
WEBP_DSP_INIT_VARS(name##_body); \
static WEBP_TSAN_IGNORE_FUNCTION void name##_body(void); \ static WEBP_TSAN_IGNORE_FUNCTION void name##_body(void); \
WEBP_TSAN_IGNORE_FUNCTION void name(void) { WEBP_DSP_INIT(name##_body); } \ WEBP_TSAN_IGNORE_FUNCTION void name(void) { WEBP_DSP_INIT(name##_body); } \
static WEBP_TSAN_IGNORE_FUNCTION void name##_body(void) static WEBP_TSAN_IGNORE_FUNCTION void name##_body(void)