scudo: Simplify AtomicOptions::setFillContentsMode. NFCI.
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 2 Oct 2020 17:20:31 +0000 (10:20 -0700)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 2 Oct 2020 17:52:41 +0000 (10:52 -0700)
Differential Revision: https://reviews.llvm.org/D88747

compiler-rt/lib/scudo/standalone/options.h

index 4f387a3..3051e8a 100644 (file)
@@ -54,16 +54,14 @@ public:
   }
 
   void setFillContentsMode(FillContentsMode FillContents) {
-    while (1) {
-      u32 Opts = atomic_load(&Val, memory_order_relaxed);
-      u32 NewOpts = Opts;
+    u32 Opts = atomic_load(&Val, memory_order_relaxed), NewOpts;
+    do {
+      NewOpts = Opts;
       NewOpts &= ~(3U << static_cast<u32>(OptionBit::FillContents0of2));
       NewOpts |= static_cast<u32>(FillContents)
                  << static_cast<u32>(OptionBit::FillContents0of2);
-      if (atomic_compare_exchange_strong(&Val, &Opts, NewOpts,
-                                         memory_order_relaxed))
-        break;
-    }
+    } while (!atomic_compare_exchange_strong(&Val, &Opts, NewOpts,
+                                             memory_order_relaxed));
   }
 };