[libc-commits] [libc] [libc] Replace `MutexLock` with `cpp::lock_guard` (PR #89340)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Apr 22 13:20:21 PDT 2024


================
@@ -12,56 +12,72 @@
 using LIBC_NAMESPACE::cpp::adopt_lock;
 using LIBC_NAMESPACE::cpp::lock_guard;
 
-static const int SIGABRT = 6;
-
 // Simple struct for testing cpp::lock_guard. It defines methods 'lock' and
 // 'unlock' which are required for the cpp::lock_guard class template.
 struct Mutex {
-  Mutex() : locked(false) {}
+  // Flag to show whether this mutex is locked.
+  bool locked;
+
+  // Flag to show if this mutex has been double locked.
+  bool double_locked;
+
+  // Flag to show if this mutex has been double unlocked.
+  bool double_unlocked;
+
+  Mutex()
+    : locked(false)
+    , double_locked(false)
+    , double_unlocked(false)
+  {}
 
   void lock() {
     if (locked) {
-      // Sends signal 6.
-      abort();
+      double_locked = true;
     }
     locked = true;
   }
 
   void unlock() {
     if (!locked) {
-      // Sends signal 6.
-      abort();
+      double_unlocked = true;
     }
----------------
nickdesaulniers wrote:

You can remove `{}` for single statement conditions. This is LLVM tree wide style.
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements

https://github.com/llvm/llvm-project/pull/89340


More information about the libc-commits mailing list