From 05f177c5e6d77db174fff8791fe29ada78b2fbc9 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Sun, 3 Jun 2018 21:11:35 +0200
Subject: [PATCH] Added some 'const' decoration and better documentation to the
 atomics to make them easier to follow.

---
 src/atomic.h | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/atomic.h b/src/atomic.h
index cb73c9f26a..69df59e9fb 100644
--- a/src/atomic.h
+++ b/src/atomic.h
@@ -39,13 +39,16 @@
  *
  * This is a text-book implementation based on an atomic CAS.
  *
+ * We create a temporary union to cope with the int-only atomic CAS
+ * and the floating-point min that we want.
+ *
  * @param address The address to update.
  * @param y The value to update the address with.
  */
 __attribute__((always_inline)) INLINE static void atomic_min_f(
-    volatile float* address, float y) {
+    volatile float *const address, const float y) {
 
-  int* int_ptr = (int*)address;
+  int *const int_ptr = (int *)address;
 
   typedef union {
     float as_float;
@@ -67,13 +70,16 @@ __attribute__((always_inline)) INLINE static void atomic_min_f(
  *
  * This is a text-book implementation based on an atomic CAS.
  *
+ * We create a temporary union to cope with the int-only atomic CAS
+ * and the floating-point max that we want.
+ *
  * @param address The address to update.
  * @param y The value to update the address with.
  */
 __attribute__((always_inline)) INLINE static void atomic_max_f(
-    volatile float* address, float y) {
+    volatile float *const address, const float y) {
 
-  int* int_ptr = (int*)address;
+  int *const int_ptr = (int *)address;
 
   typedef union {
     float as_float;
@@ -95,13 +101,16 @@ __attribute__((always_inline)) INLINE static void atomic_max_f(
  *
  * This is a text-book implementation based on an atomic CAS.
  *
+ * We create a temporary union to cope with the int-only atomic CAS
+ * and the floating-point add that we want.
+ *
  * @param address The address to update.
  * @param y The value to update the address with.
  */
 __attribute__((always_inline)) INLINE static void atomic_add_f(
-    volatile float* address, float y) {
+    volatile float *const address, const float y) {
 
-  int* int_ptr = (int*)address;
+  int *const int_ptr = (int *)address;
 
   typedef union {
     float as_float;
-- 
GitLab