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:
Pascal Massimino
2015-01-05 06:51:54 -08:00
parent 4e2589ff81
commit a437694a17
7 changed files with 40 additions and 1 deletions

View File

@ -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;
}
//-----------------------------------------------------------------------------