From a437694a17e2ee4c68bf0abba8e45e0dfd2a8e27 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Mon, 5 Jan 2015 06:51:54 -0800 Subject: [PATCH] multi-thread fix: lock each entry points with a static var we compare the current VP8GetCPUInfo pointer to the last used. This is less code overall and each implementation is still testable separately (by just changing VP8GetCPUInfo, but not a separate threads!) Change-Id: Ia13fa8ffc4561a884508f6ab71ed0d1b9f1ce59b --- src/dsp/alpha_processing.c | 5 +++++ src/dsp/argb.c | 5 +++++ src/dsp/dec.c | 6 +++++- src/dsp/enc.c | 5 +++++ src/dsp/lossless.c | 5 +++++ src/dsp/upsampling.c | 10 ++++++++++ src/dsp/yuv.c | 5 +++++ 7 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/dsp/alpha_processing.c b/src/dsp/alpha_processing.c index ae6cc8cd..20c245d8 100644 --- a/src/dsp/alpha_processing.c +++ b/src/dsp/alpha_processing.c @@ -347,7 +347,11 @@ extern void VP8FiltersInitMIPSdspR2(void); extern void WebPInitAlphaProcessingMIPSdspR2(void); extern void WebPInitAlphaProcessingSSE2(void); +static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; + WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessing(void) { + if (last_cpuinfo_used == VP8GetCPUInfo) return; + WebPMultARGBRow = WebPMultARGBRowC; WebPMultRow = WebPMultRowC; WebPApplyAlphaMultiply = ApplyAlphaMultiply; @@ -370,4 +374,5 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessing(void) { } #endif } + last_cpuinfo_used = VP8GetCPUInfo; } diff --git a/src/dsp/argb.c b/src/dsp/argb.c index bdbdd677..bb67ac9a 100644 --- a/src/dsp/argb.c +++ b/src/dsp/argb.c @@ -42,7 +42,11 @@ void (*VP8PackRGB)(const uint8_t*, const uint8_t*, const uint8_t*, extern void VP8EncDspARGBInitMIPSdspR2(void); +static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; + WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInit(void) { + if (last_cpuinfo_used == VP8GetCPUInfo) return; + VP8PackARGB = PackARGB; VP8PackRGB = PackRGB; @@ -54,4 +58,5 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInit(void) { } #endif } + last_cpuinfo_used = VP8GetCPUInfo; } diff --git a/src/dsp/dec.c b/src/dsp/dec.c index 283d0f9e..91c01c0d 100644 --- a/src/dsp/dec.c +++ b/src/dsp/dec.c @@ -684,7 +684,11 @@ extern void VP8DspInitNEON(void); extern void VP8DspInitMIPS32(void); extern void VP8DspInitMIPSdspR2(void); +static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; + WEBP_TSAN_IGNORE_FUNCTION void VP8DspInit(void) { + if (last_cpuinfo_used == VP8GetCPUInfo) return; + VP8InitClipTables(); VP8TransformWHT = TransformWHT; @@ -749,5 +753,5 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8DspInit(void) { } #endif } + last_cpuinfo_used = VP8GetCPUInfo; } - diff --git a/src/dsp/enc.c b/src/dsp/enc.c index c22986ae..fc2b62ab 100644 --- a/src/dsp/enc.c +++ b/src/dsp/enc.c @@ -727,7 +727,11 @@ extern void VP8EncDspInitNEON(void); extern void VP8EncDspInitMIPS32(void); extern void VP8EncDspInitMIPSdspR2(void); +static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; + WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspInit(void) { + if (last_cpuinfo_used == VP8GetCPUInfo) return; + VP8DspInit(); // common inverse transforms InitTables(); @@ -779,4 +783,5 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspInit(void) { } #endif } + last_cpuinfo_used = VP8GetCPUInfo; } diff --git a/src/dsp/lossless.c b/src/dsp/lossless.c index 31a8ad4c..b32bff7e 100644 --- a/src/dsp/lossless.c +++ b/src/dsp/lossless.c @@ -1745,7 +1745,11 @@ extern void VP8LDspInitNEON(void); extern void VP8LDspInitMIPS32(void); extern void VP8LDspInitMIPSdspR2(void); +static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; + WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInit(void) { + if (last_cpuinfo_used == VP8GetCPUInfo) return; + memcpy(VP8LPredictors, kPredictorsC, sizeof(VP8LPredictors)); VP8LSubtractGreenFromBlueAndRed = VP8LSubtractGreenFromBlueAndRed_C; @@ -1797,6 +1801,7 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInit(void) { } #endif } + last_cpuinfo_used = VP8GetCPUInfo; } //------------------------------------------------------------------------------ diff --git a/src/dsp/upsampling.c b/src/dsp/upsampling.c index 7d6dd096..807ee8d6 100644 --- a/src/dsp/upsampling.c +++ b/src/dsp/upsampling.c @@ -173,7 +173,11 @@ WebPYUV444Converter WebPYUV444Converters[MODE_LAST]; extern WEBP_TSAN_IGNORE_FUNCTION void WebPInitYUV444ConvertersMIPSdspR2(void); +static volatile VP8CPUInfo last_cpuinfo_used1 = (VP8CPUInfo)&last_cpuinfo_used1; + WEBP_TSAN_IGNORE_FUNCTION void WebPInitYUV444Converters(void) { + if (last_cpuinfo_used1 == VP8GetCPUInfo) return; + WebPYUV444Converters[MODE_RGB] = Yuv444ToRgb; WebPYUV444Converters[MODE_RGBA] = Yuv444ToRgba; WebPYUV444Converters[MODE_BGR] = Yuv444ToBgr; @@ -193,6 +197,7 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitYUV444Converters(void) { } #endif } + last_cpuinfo_used1 = VP8GetCPUInfo; } //------------------------------------------------------------------------------ @@ -202,7 +207,11 @@ extern WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplersSSE2(void); extern WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplersNEON(void); extern WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplersMIPSdspR2(void); +static volatile VP8CPUInfo last_cpuinfo_used2 = (VP8CPUInfo)&last_cpuinfo_used2; + WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplers(void) { + if (last_cpuinfo_used2 == VP8GetCPUInfo) return; + #ifdef FANCY_UPSAMPLING WebPUpsamplers[MODE_RGB] = UpsampleRgbLinePair; WebPUpsamplers[MODE_RGBA] = UpsampleRgbaLinePair; @@ -235,6 +244,7 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplers(void) { #endif } #endif // FANCY_UPSAMPLING + last_cpuinfo_used2 = VP8GetCPUInfo; } //------------------------------------------------------------------------------ diff --git a/src/dsp/yuv.c b/src/dsp/yuv.c index e7f4f415..558ffd43 100644 --- a/src/dsp/yuv.c +++ b/src/dsp/yuv.c @@ -124,7 +124,11 @@ extern WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplersSSE2(void); extern WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplersMIPS32(void); extern WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplersMIPSdspR2(void); +static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; + WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplers(void) { + if (last_cpuinfo_used == VP8GetCPUInfo) return; + WebPSamplers[MODE_RGB] = YuvToRgbRow; WebPSamplers[MODE_RGBA] = YuvToRgbaRow; WebPSamplers[MODE_BGR] = YuvToBgrRow; @@ -155,6 +159,7 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplers(void) { } #endif // WEBP_USE_MIPS_DSP_R2 } + last_cpuinfo_used = VP8GetCPUInfo; } //-----------------------------------------------------------------------------