Module Name:    src
Committed By:   skrll
Date:           Sat May 14 05:35:55 UTC 2022

Modified Files:
        src/common/lib/libc/atomic: atomic_c11_compare_exchange_cas_16.c
            atomic_c11_compare_exchange_cas_32.c
            atomic_c11_compare_exchange_cas_8.c


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
    src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c \
    src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c \
    src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c
diff -u src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c:1.3 src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c:1.4
--- src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c:1.3	Mon Sep  7 00:52:19 2020
+++ src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c	Sat May 14 05:35:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: atomic_c11_compare_exchange_cas_16.c,v 1.3 2020/09/07 00:52:19 mrg Exp $	*/
+/*	$NetBSD: atomic_c11_compare_exchange_cas_16.c,v 1.4 2022/05/14 05:35:55 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -44,12 +44,17 @@ __atomic_compare_exchange_2(volatile voi
     void *expected, uint16_t desired,
     bool weak, int success, int failure)
 {
-	uint16_t old = *(uint16_t *)expected;
+	uint16_t * const ep = expected;
+	const uint16_t old = *ep;
 
 	/*
 	 * Ignore the details (weak, memory model on success and failure)
 	 * and just do the cas. If we get here the compiler couldn't
 	 * do better and it mostly will not matter at all.
 	 */
-	return atomic_cas_16(mem, old, desired) == old;
+	const uint16_t prev = atomic_cas_16(mem, old, desired);
+	if (prev == old)
+		return true;
+	*ep = prev;
+	return false;
 }
Index: src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c
diff -u src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c:1.3 src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c:1.4
--- src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c:1.3	Mon Sep  7 00:52:19 2020
+++ src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c	Sat May 14 05:35:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: atomic_c11_compare_exchange_cas_32.c,v 1.3 2020/09/07 00:52:19 mrg Exp $	*/
+/*	$NetBSD: atomic_c11_compare_exchange_cas_32.c,v 1.4 2022/05/14 05:35:55 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -44,12 +44,17 @@ __atomic_compare_exchange_4(volatile voi
     void *expected, uint32_t desired,
     bool weak, int success, int failure)
 {
-	uint32_t old = *(uint32_t *)expected;
+	uint32_t * const ep = expected;
+	const uint32_t old = *ep;
 
 	/*
 	 * Ignore the details (weak, memory model on success and failure)
 	 * and just do the cas. If we get here the compiler couldn't
 	 * do better and it mostly will not matter at all.
 	 */
-	return atomic_cas_32(mem, old, desired) == old;
+	const uint32_t prev = atomic_cas_8(mem, old, desired);
+	if (prev == old)
+		return true;
+	*ep = prev;
+	return false;
 }
Index: src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c
diff -u src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c:1.3 src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c:1.4
--- src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c:1.3	Mon Sep  7 00:52:19 2020
+++ src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c	Sat May 14 05:35:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: atomic_c11_compare_exchange_cas_8.c,v 1.3 2020/09/07 00:52:19 mrg Exp $	*/
+/*	$NetBSD: atomic_c11_compare_exchange_cas_8.c,v 1.4 2022/05/14 05:35:55 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -44,12 +44,17 @@ __atomic_compare_exchange_1(volatile voi
     void *expected, uint8_t desired,
     bool weak, int success, int failure)
 {
-	uint8_t old = *(uint8_t *)expected;
+	uint8_t * const ep = expected;
+	const uint8_t old = *ep;
 
 	/*
 	 * Ignore the details (weak, memory model on success and failure)
 	 * and just do the cas. If we get here the compiler couldn't
 	 * do better and it mostly will not matter at all.
 	 */
-	return atomic_cas_8(mem, old, desired) == old;
+	const uint8_t prev = atomic_cas_8(mem, old, desired);
+	if (prev == old)
+		return true;
+	*ep = prev;
+	return false;
 }

Reply via email to