[libc-commits] [libc] [libc] Replace `MutexLock` with `cpp::lock_guard` (PR #89340)
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Fri May 3 07:36:07 PDT 2024
================
@@ -0,0 +1,79 @@
+//===-- Unittests for mutex -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/CPP/mutex.h"
+#include "test/UnitTest/Test.h"
+
+using LIBC_NAMESPACE::cpp::adopt_lock;
+using LIBC_NAMESPACE::cpp::lock_guard;
+
+// 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 {
+ // 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) {}
----------------
gchatelet wrote:
If you default initialize the variables you can remove the constructor.
https://github.com/llvm/llvm-project/pull/89340
More information about the libc-commits
mailing list