Make SIMD capability variables thread-local ...

... on platforms that support TLS, which should include all
currently-supported platforms
(https://libjpeg-turbo.org/Documentation/OfficialBinaries)

Addresses a concern raised in #87

Although it is still my opinion that the data race in init_simd() was
innocuous, we can now fix it for free thanks to
ae87a95861, so why not?
This commit is contained in:
DRC
2022-10-03 19:46:09 -05:00
parent 2cad2169ae
commit f579cc11b3
7 changed files with 16 additions and 30 deletions

View File

@@ -32,13 +32,11 @@
#define IS_ALIGNED_SSE(ptr) (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */
#define IS_ALIGNED_AVX(ptr) (IS_ALIGNED(ptr, 5)) /* 32 byte alignment */
static unsigned int simd_support = (unsigned int)(~0);
static unsigned int simd_huffman = 1;
static THREAD_LOCAL unsigned int simd_support = (unsigned int)(~0);
static THREAD_LOCAL unsigned int simd_huffman = 1;
/*
* Check what SIMD accelerations are supported.
*
* FIXME: This code is racy under a multi-threaded environment.
*/
LOCAL(void)
init_simd(void)