Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/sys Rework modified atomic_load/store_* to work on const...



details:   https://anonhg.NetBSD.org/src/rev/167a7d98860a
branches:  trunk
changeset: 846783:167a7d98860a
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 01 15:28:02 2019 +0000

description:
Rework modified atomic_load/store_* to work on const pointers.

diffstat:

 sys/sys/atomic.h |  30 ++++++++++++++++--------------
 1 files changed, 16 insertions(+), 14 deletions(-)

diffs (71 lines):

diff -r 92977150fde8 -r 167a7d98860a sys/sys/atomic.h
--- a/sys/sys/atomic.h  Sun Dec 01 15:27:58 2019 +0000
+++ b/sys/sys/atomic.h  Sun Dec 01 15:28:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic.h,v 1.19 2019/12/01 08:15:58 maxv Exp $ */
+/*     $NetBSD: atomic.h,v 1.20 2019/12/01 15:28:02 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@@ -414,13 +414,18 @@
 #ifdef KCSAN
 void kcsan_atomic_load(const volatile void *, void *, int);
 void kcsan_atomic_store(volatile void *, const void *, int);
-#define __DO_ATOMIC_LOAD(p, v) \
-       kcsan_atomic_load(p, __UNVOLATILE(&v), sizeof(v))
+#define __BEGIN_ATOMIC_LOAD(p, v) \
+       union { __typeof__(*(p)) __al_val; char __al_buf[1]; } v; \
+       kcsan_atomic_load(p, v.__al_buf, sizeof(v.__al_val))
+#define __END_ATOMIC_LOAD(v) \
+       (v).__al_val
 #define __DO_ATOMIC_STORE(p, v) \
        kcsan_atomic_store(p, __UNVOLATILE(&v), sizeof(v))
 #else
-#define __DO_ATOMIC_LOAD(p, v) \
-       v = *p
+#define __BEGIN_ATOMIC_LOAD(p, v) \
+       __typeof__(*(p)) v = *(p)
+#define __END_ATOMIC_LOAD(v) \
+       v
 #define __DO_ATOMIC_STORE(p, v) \
        *p = v
 #endif
@@ -428,20 +433,18 @@
 #define        atomic_load_relaxed(p)                                                \
 ({                                                                           \
        const volatile __typeof__(*(p)) *__al_ptr = (p);                      \
-       __typeof__(*(p)) __al_val;                                            \
        __ATOMIC_PTR_CHECK(__al_ptr);                                         \
-       __DO_ATOMIC_LOAD(__al_ptr, __al_val);                                 \
-       __al_val;                                                             \
+       __BEGIN_ATOMIC_LOAD(__al_ptr, __al_val);                              \
+       __END_ATOMIC_LOAD(__al_val);                                          \
 })
 
 #define        atomic_load_consume(p)                                                \
 ({                                                                           \
        const volatile __typeof__(*(p)) *__al_ptr = (p);                      \
-       __typeof__(*(p)) __al_val;                                            \
        __ATOMIC_PTR_CHECK(__al_ptr);                                         \
-       __DO_ATOMIC_LOAD(__al_ptr, __al_val);                                 \
+       __BEGIN_ATOMIC_LOAD(__al_ptr, __al_val);                              \
        membar_datadep_consumer();                                            \
-       __al_val;                                                             \
+       __END_ATOMIC_LOAD(__al_val);                                          \
 })
 
 /*
@@ -453,11 +456,10 @@
 #define        atomic_load_acquire(p)                                                \
 ({                                                                           \
        const volatile __typeof__(*(p)) *__al_ptr = (p);                      \
-       __typeof__(*(p)) __al_val;                                            \
        __ATOMIC_PTR_CHECK(__al_ptr);                                         \
-       __DO_ATOMIC_LOAD(__al_ptr, __al_val);                                 \
+       __BEGIN_ATOMIC_LOAD(__al_ptr, __al_val);                              \
        membar_sync();                                                        \
-       __al_val;                                                             \
+       __END_ATOMIC_LOAD(__al_val);                                          \
 })
 
 #define        atomic_store_relaxed(p,v)                                             \



Home | Main Index | Thread Index | Old Index