Browse Source

do not use special gcc feature

Kajetan Johannes Hammerle 2 years ago
parent
commit
803590c48f
1 changed files with 12 additions and 13 deletions
  1. 12 13
      include/enet.h

+ 12 - 13
include/enet.h

@@ -1148,7 +1148,7 @@ extern "C" {
     #define ENET_ATOMIC_READ(variable) enet_at_atomic_read((char *)(variable), ENET_ATOMIC_SIZEOF(variable))
     #define ENET_ATOMIC_READ(variable) enet_at_atomic_read((char *)(variable), ENET_ATOMIC_SIZEOF(variable))
     #define ENET_ATOMIC_WRITE(variable, new_val)                                                            \
     #define ENET_ATOMIC_WRITE(variable, new_val)                                                            \
         enet_at_atomic_write((char *)(variable), (int64_t)(new_val), ENET_ATOMIC_SIZEOF(variable))
         enet_at_atomic_write((char *)(variable), (int64_t)(new_val), ENET_ATOMIC_SIZEOF(variable))
-    #define ENET_ATOMIC_CAS(variable, old_value, new_val)                                                   \
+    #define ENET_ATOMIC_CAS(variable, old_value, new_val, assign)                                           \
         enet_at_atomic_cas((char *)(variable), (int64_t)(new_val), (int64_t)(old_value),                    \
         enet_at_atomic_cas((char *)(variable), (int64_t)(new_val), (int64_t)(old_value),                    \
                       ENET_ATOMIC_SIZEOF(variable))
                       ENET_ATOMIC_SIZEOF(variable))
     #define ENET_ATOMIC_INC(variable) enet_at_atomic_inc((char *)(variable), 1, ENET_ATOMIC_SIZEOF(variable))
     #define ENET_ATOMIC_INC(variable) enet_at_atomic_inc((char *)(variable), 1, ENET_ATOMIC_SIZEOF(variable))
@@ -1185,13 +1185,13 @@ extern "C" {
            potentially lost data. Replace the code with the equivalent non-sync code. */
            potentially lost data. Replace the code with the equivalent non-sync code. */
         #ifdef __clang_analyzer__
         #ifdef __clang_analyzer__
 
 
-        #define ENET_ATOMIC_CAS(ptr, old_value, new_value)                                                      \
+        #define ENET_ATOMIC_CAS(ptr, old_value, new_value, assign)                                         \
             ({                                                                                             \
             ({                                                                                             \
-                typeof(*(ptr)) ENET_ATOMIC_CAS_old_actual_ = (*(ptr));                                          \
+                typeof(*(ptr)) ENET_ATOMIC_CAS_old_actual_ = (*(ptr));                                     \
                 if (ATOMIC_CAS_old_actual_ == (old_value)) {                                               \
                 if (ATOMIC_CAS_old_actual_ == (old_value)) {                                               \
                     *(ptr) = new_value;                                                                    \
                     *(ptr) = new_value;                                                                    \
                 }                                                                                          \
                 }                                                                                          \
-                ENET_ATOMIC_CAS_old_actual_;                                                                    \
+                ENET_ATOMIC_CAS_old_actual_;                                                               \
             })
             })
 
 
         #else
         #else
@@ -1202,13 +1202,12 @@ extern "C" {
 
 
            TODO We should return bool here instead of the old value to avoid the ABA
            TODO We should return bool here instead of the old value to avoid the ABA
            problem. */
            problem. */
-        #define ENET_ATOMIC_CAS(ptr, old_value, new_value)                                                      \
-            ({                                                                                             \
-                typeof(*(ptr)) ENET_ATOMIC_CAS_expected_ = (old_value);                                         \
-                __atomic_compare_exchange_n((ptr), &ENET_ATOMIC_CAS_expected_, (new_value), false,              \
-                                            __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);                           \
-                ENET_ATOMIC_CAS_expected_;                                                                      \
-            })
+        #define ENET_ATOMIC_CAS(ptr, old_value, new_value, assign)                                         \
+            0;                                                                                             \
+            typeof(*(ptr)) ENET_ATOMIC_CAS_expected_ = (old_value);                                        \
+            __atomic_compare_exchange_n((ptr), &ENET_ATOMIC_CAS_expected_, (new_value), false,             \
+                                        __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);                               \
+            assign = ENET_ATOMIC_CAS_expected_;                                                                 
 
 
         #endif /* __clang_analyzer__ */
         #endif /* __clang_analyzer__ */
 
 
@@ -1222,7 +1221,7 @@ extern "C" {
         #define ENET_ATOMIC_READ(variable) __sync_fetch_and_add(variable, 0)
         #define ENET_ATOMIC_READ(variable) __sync_fetch_and_add(variable, 0)
         #define ENET_ATOMIC_WRITE(variable, new_val)                                                            \
         #define ENET_ATOMIC_WRITE(variable, new_val)                                                            \
             (void) __sync_val_compare_and_swap((variable), *(variable), (new_val))
             (void) __sync_val_compare_and_swap((variable), *(variable), (new_val))
-        #define ENET_ATOMIC_CAS(variable, old_value, new_val)                                                   \
+        #define ENET_ATOMIC_CAS(variable, old_value, new_val, assign)                                           \
             __sync_val_compare_and_swap((variable), (old_value), (new_val))
             __sync_val_compare_and_swap((variable), (old_value), (new_val))
         #define ENET_ATOMIC_INC(variable) __sync_fetch_and_add((variable), 1)
         #define ENET_ATOMIC_INC(variable) __sync_fetch_and_add((variable), 1)
         #define ENET_ATOMIC_DEC(variable) __sync_fetch_and_sub((variable), 1)
         #define ENET_ATOMIC_DEC(variable) __sync_fetch_and_sub((variable), 1)
@@ -5004,7 +5003,7 @@ extern "C" {
             // Set the value of the start_time_ns, such that the first timestamp
             // Set the value of the start_time_ns, such that the first timestamp
             // is at 1ms. This ensures 0 remains a special value.
             // is at 1ms. This ensures 0 remains a special value.
             uint64_t want_value = current_time_ns - 1 * ns_in_ms;
             uint64_t want_value = current_time_ns - 1 * ns_in_ms;
-            uint64_t old_value = ENET_ATOMIC_CAS(&start_time_ns, 0, want_value);
+            uint64_t old_value = ENET_ATOMIC_CAS(&start_time_ns, 0, want_value, old_value);
             offset_ns = old_value == 0 ? want_value : old_value;
             offset_ns = old_value == 0 ? want_value : old_value;
         }
         }