[PATCH] [C++11] Replace LLVM atomics with std::atomic.

Ahmed Charles acharles at outlook.com
Sun Mar 2 17:19:22 PST 2014



================
Comment at: include/llvm/ADT/Statistic.h:100-113
@@ -101,8 +99,16 @@
   const Statistic &operator*=(const unsigned &V) {
-    sys::AtomicMul(&Value, V);
+    unsigned Original, Result;
+    do {
+      Original = Value;
+      Result = Original * V;
+    } while (!Value.compare_exchange_strong(Original, Result));
     return init();
   }
 
   const Statistic &operator/=(const unsigned &V) {
-    sys::AtomicDiv(&Value, V);
+    unsigned Original, Result;
+    do {
+      Original = Value;
+      Result = Original / V;
+    } while (!Value.compare_exchange_strong(Original, Result));
     return init();
----------------
I read the standard on the definition of compare_exchange_strong and compare_exchange_weak and I don't seem to know enough to decide one way or another. I'm just curious about the rationale applied here.


http://llvm-reviews.chandlerc.com/D2915



More information about the llvm-commits mailing list