Skip to content

Commit 0e27348

Browse files
authored
Try to access 'support' only atomically (#520)
1 parent c438bee commit 0e27348

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/isadetection.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,23 @@ static inline uint32_t dynamic_croaring_detect_supported_architectures(void) {
198198
if (ebx & cpuid_avx512f_bit) {
199199
host_isa |= CROARING_AVX512F;
200200
}
201-
201+
202202
if (ebx & cpuid_avx512bw_bit) {
203203
host_isa |= CROARING_AVX512BW;
204204
}
205-
205+
206206
if (ebx & cpuid_avx512dq_bit) {
207207
host_isa |= CROARING_AVX512DQ;
208208
}
209-
209+
210210
if (ecx & cpuid_avx512vbmi2_bit) {
211211
host_isa |= CROARING_AVX512VBMI2;
212212
}
213-
213+
214214
if (ecx & cpuid_avx512bitalg_bit) {
215215
host_isa |= CROARING_AVX512BITALG;
216216
}
217-
217+
218218
if (ecx & cpuid_avx512vpopcntdq_bit) {
219219
host_isa |= CROARING_AVX512VPOPCNTDQ;
220220
}
@@ -267,7 +267,11 @@ int croaring_hardware_support(void) {
267267
#elif defined(__AVX2__)
268268

269269
int croaring_hardware_support(void) {
270-
static int support = 0xFFFFFFF;
270+
static
271+
#if CROARING_ATOMIC_IMPL == CROARING_ATOMIC_IMPL_C
272+
_Atomic
273+
#endif
274+
int support = 0xFFFFFFF;
271275
if(support == 0xFFFFFFF) {
272276
bool avx512_support = false;
273277
#if CROARING_COMPILER_SUPPORTS_AVX512
@@ -281,7 +285,11 @@ int croaring_hardware_support(void) {
281285
#else
282286

283287
int croaring_hardware_support(void) {
284-
static int support = 0xFFFFFFF;
288+
static
289+
#if CROARING_ATOMIC_IMPL == CROARING_ATOMIC_IMPL_C
290+
_Atomic
291+
#endif
292+
int support = 0xFFFFFFF;
285293
if(support == 0xFFFFFFF) {
286294
bool has_avx2 = (croaring_detect_supported_architectures() & CROARING_AVX2) == CROARING_AVX2;
287295
bool has_avx512 = false;

0 commit comments

Comments
 (0)