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
This commit is contained in:
		| @@ -347,7 +347,11 @@ extern void VP8FiltersInitMIPSdspR2(void); | |||||||
| extern void WebPInitAlphaProcessingMIPSdspR2(void); | extern void WebPInitAlphaProcessingMIPSdspR2(void); | ||||||
| extern void WebPInitAlphaProcessingSSE2(void); | extern void WebPInitAlphaProcessingSSE2(void); | ||||||
|  |  | ||||||
|  | static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; | ||||||
|  |  | ||||||
| WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessing(void) { | WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessing(void) { | ||||||
|  |   if (last_cpuinfo_used == VP8GetCPUInfo) return; | ||||||
|  |  | ||||||
|   WebPMultARGBRow = WebPMultARGBRowC; |   WebPMultARGBRow = WebPMultARGBRowC; | ||||||
|   WebPMultRow = WebPMultRowC; |   WebPMultRow = WebPMultRowC; | ||||||
|   WebPApplyAlphaMultiply = ApplyAlphaMultiply; |   WebPApplyAlphaMultiply = ApplyAlphaMultiply; | ||||||
| @@ -370,4 +374,5 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessing(void) { | |||||||
|     } |     } | ||||||
| #endif | #endif | ||||||
|   } |   } | ||||||
|  |   last_cpuinfo_used = VP8GetCPUInfo; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -42,7 +42,11 @@ void (*VP8PackRGB)(const uint8_t*, const uint8_t*, const uint8_t*, | |||||||
|  |  | ||||||
| extern void VP8EncDspARGBInitMIPSdspR2(void); | extern void VP8EncDspARGBInitMIPSdspR2(void); | ||||||
|  |  | ||||||
|  | static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; | ||||||
|  |  | ||||||
| WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInit(void) { | WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInit(void) { | ||||||
|  |   if (last_cpuinfo_used == VP8GetCPUInfo) return; | ||||||
|  |  | ||||||
|   VP8PackARGB = PackARGB; |   VP8PackARGB = PackARGB; | ||||||
|   VP8PackRGB = PackRGB; |   VP8PackRGB = PackRGB; | ||||||
|  |  | ||||||
| @@ -54,4 +58,5 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInit(void) { | |||||||
|     } |     } | ||||||
| #endif | #endif | ||||||
|   } |   } | ||||||
|  |   last_cpuinfo_used = VP8GetCPUInfo; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -684,7 +684,11 @@ extern void VP8DspInitNEON(void); | |||||||
| extern void VP8DspInitMIPS32(void); | extern void VP8DspInitMIPS32(void); | ||||||
| extern void VP8DspInitMIPSdspR2(void); | extern void VP8DspInitMIPSdspR2(void); | ||||||
|  |  | ||||||
|  | static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; | ||||||
|  |  | ||||||
| WEBP_TSAN_IGNORE_FUNCTION void VP8DspInit(void) { | WEBP_TSAN_IGNORE_FUNCTION void VP8DspInit(void) { | ||||||
|  |   if (last_cpuinfo_used == VP8GetCPUInfo) return; | ||||||
|  |  | ||||||
|   VP8InitClipTables(); |   VP8InitClipTables(); | ||||||
|  |  | ||||||
|   VP8TransformWHT = TransformWHT; |   VP8TransformWHT = TransformWHT; | ||||||
| @@ -749,5 +753,5 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8DspInit(void) { | |||||||
|     } |     } | ||||||
| #endif | #endif | ||||||
|   } |   } | ||||||
|  |   last_cpuinfo_used = VP8GetCPUInfo; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -727,7 +727,11 @@ extern void VP8EncDspInitNEON(void); | |||||||
| extern void VP8EncDspInitMIPS32(void); | extern void VP8EncDspInitMIPS32(void); | ||||||
| extern void VP8EncDspInitMIPSdspR2(void); | extern void VP8EncDspInitMIPSdspR2(void); | ||||||
|  |  | ||||||
|  | static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; | ||||||
|  |  | ||||||
| WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspInit(void) { | WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspInit(void) { | ||||||
|  |   if (last_cpuinfo_used == VP8GetCPUInfo) return; | ||||||
|  |  | ||||||
|   VP8DspInit();  // common inverse transforms |   VP8DspInit();  // common inverse transforms | ||||||
|   InitTables(); |   InitTables(); | ||||||
|  |  | ||||||
| @@ -779,4 +783,5 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspInit(void) { | |||||||
|     } |     } | ||||||
| #endif | #endif | ||||||
|   } |   } | ||||||
|  |   last_cpuinfo_used = VP8GetCPUInfo; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1745,7 +1745,11 @@ extern void VP8LDspInitNEON(void); | |||||||
| extern void VP8LDspInitMIPS32(void); | extern void VP8LDspInitMIPS32(void); | ||||||
| extern void VP8LDspInitMIPSdspR2(void); | extern void VP8LDspInitMIPSdspR2(void); | ||||||
|  |  | ||||||
|  | static volatile VP8CPUInfo last_cpuinfo_used = (VP8CPUInfo)&last_cpuinfo_used; | ||||||
|  |  | ||||||
| WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInit(void) { | WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInit(void) { | ||||||
|  |   if (last_cpuinfo_used == VP8GetCPUInfo) return; | ||||||
|  |  | ||||||
|   memcpy(VP8LPredictors, kPredictorsC, sizeof(VP8LPredictors)); |   memcpy(VP8LPredictors, kPredictorsC, sizeof(VP8LPredictors)); | ||||||
|  |  | ||||||
|   VP8LSubtractGreenFromBlueAndRed = VP8LSubtractGreenFromBlueAndRed_C; |   VP8LSubtractGreenFromBlueAndRed = VP8LSubtractGreenFromBlueAndRed_C; | ||||||
| @@ -1797,6 +1801,7 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInit(void) { | |||||||
|     } |     } | ||||||
| #endif | #endif | ||||||
|   } |   } | ||||||
|  |   last_cpuinfo_used = VP8GetCPUInfo; | ||||||
| } | } | ||||||
|  |  | ||||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||||
|   | |||||||
| @@ -173,7 +173,11 @@ WebPYUV444Converter WebPYUV444Converters[MODE_LAST]; | |||||||
|  |  | ||||||
| extern WEBP_TSAN_IGNORE_FUNCTION void WebPInitYUV444ConvertersMIPSdspR2(void); | 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) { | WEBP_TSAN_IGNORE_FUNCTION void WebPInitYUV444Converters(void) { | ||||||
|  |   if (last_cpuinfo_used1 == VP8GetCPUInfo) return; | ||||||
|  |  | ||||||
|   WebPYUV444Converters[MODE_RGB]       = Yuv444ToRgb; |   WebPYUV444Converters[MODE_RGB]       = Yuv444ToRgb; | ||||||
|   WebPYUV444Converters[MODE_RGBA]      = Yuv444ToRgba; |   WebPYUV444Converters[MODE_RGBA]      = Yuv444ToRgba; | ||||||
|   WebPYUV444Converters[MODE_BGR]       = Yuv444ToBgr; |   WebPYUV444Converters[MODE_BGR]       = Yuv444ToBgr; | ||||||
| @@ -193,6 +197,7 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitYUV444Converters(void) { | |||||||
|     } |     } | ||||||
| #endif | #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 WebPInitUpsamplersNEON(void); | ||||||
| extern WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplersMIPSdspR2(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) { | WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplers(void) { | ||||||
|  |   if (last_cpuinfo_used2 == VP8GetCPUInfo) return; | ||||||
|  |  | ||||||
| #ifdef FANCY_UPSAMPLING | #ifdef FANCY_UPSAMPLING | ||||||
|   WebPUpsamplers[MODE_RGB]       = UpsampleRgbLinePair; |   WebPUpsamplers[MODE_RGB]       = UpsampleRgbLinePair; | ||||||
|   WebPUpsamplers[MODE_RGBA]      = UpsampleRgbaLinePair; |   WebPUpsamplers[MODE_RGBA]      = UpsampleRgbaLinePair; | ||||||
| @@ -235,6 +244,7 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitUpsamplers(void) { | |||||||
| #endif | #endif | ||||||
|   } |   } | ||||||
| #endif  // FANCY_UPSAMPLING | #endif  // FANCY_UPSAMPLING | ||||||
|  |   last_cpuinfo_used2 = VP8GetCPUInfo; | ||||||
| } | } | ||||||
|  |  | ||||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||||
|   | |||||||
| @@ -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 WebPInitSamplersMIPS32(void); | ||||||
| extern WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplersMIPSdspR2(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) { | WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplers(void) { | ||||||
|  |   if (last_cpuinfo_used == VP8GetCPUInfo) return; | ||||||
|  |  | ||||||
|   WebPSamplers[MODE_RGB]       = YuvToRgbRow; |   WebPSamplers[MODE_RGB]       = YuvToRgbRow; | ||||||
|   WebPSamplers[MODE_RGBA]      = YuvToRgbaRow; |   WebPSamplers[MODE_RGBA]      = YuvToRgbaRow; | ||||||
|   WebPSamplers[MODE_BGR]       = YuvToBgrRow; |   WebPSamplers[MODE_BGR]       = YuvToBgrRow; | ||||||
| @@ -155,6 +159,7 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplers(void) { | |||||||
|     } |     } | ||||||
| #endif  // WEBP_USE_MIPS_DSP_R2 | #endif  // WEBP_USE_MIPS_DSP_R2 | ||||||
|   } |   } | ||||||
|  |   last_cpuinfo_used = VP8GetCPUInfo; | ||||||
| } | } | ||||||
|  |  | ||||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Pascal Massimino
					Pascal Massimino