From: David VaĊĦek Date: Wed, 1 Nov 2023 10:56:18 +0000 (+0100) Subject: contrib/spinlock: match the types formally and fix the C11 version X-Git-Tag: v3.4.0~268^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a65fca63b4138eb2888b4c1504b1c19f573e2c75;p=thirdparty%2Fknot-dns.git contrib/spinlock: match the types formally and fix the C11 version --- diff --git a/src/contrib/spinlock.h b/src/contrib/spinlock.h index 837f500616..db3a06ad30 100644 --- a/src/contrib/spinlock.h +++ b/src/contrib/spinlock.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 CZ.NIC, z.s.p.o. +/* Copyright (C) 2023 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -96,14 +96,15 @@ static inline void knot_spin_lock(knot_spin_t *lock) while (__sync_lock_test_and_set(lock, 1)) { } #elif defined(HAVE_ATOMIC) - int expected = 0; - while (!__atomic_compare_exchange_n(lock, &expected, 1, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED)) { - expected = 0; + bool expected = false; + while (!__atomic_compare_exchange_n(lock, &expected, true, false, + __ATOMIC_RELAXED, __ATOMIC_RELAXED)) { + expected = false; } #elif defined(HAVE_STDATOMIC) - int expected = 0; - while (!atomic_compare_exchange_strong(lock, &expected, false)) { - expected = 0; + bool expected = false; + while (!atomic_compare_exchange_strong(lock, &expected, true)) { + expected = false; } #elif defined(APPLE_SPIN_NEW) os_unfair_lock_lock(lock);