================
@@ -0,0 +1,90 @@
+//===-- WatchpointCollection.cpp 
------------------------------------------===//
+//
+// 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 "lldb/Breakpoint/WatchpointCollection.h"
+#include "lldb/Breakpoint/Watchpoint.h"
+#include "lldb/Core/ModuleList.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadSpec.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+// WatchpointCollection constructor
+WatchpointCollection::WatchpointCollection() = default;
+
+// Destructor
+WatchpointCollection::~WatchpointCollection() = default;
+
+void WatchpointCollection::Add(const WatchpointSP &wp) {
+  std::lock_guard<std::mutex> guard(m_collection_mutex);
+  m_collection.push_back(wp);
+}
+
+bool WatchpointCollection::Remove(WatchpointSP &wp) {
+  std::lock_guard<std::mutex> guard(m_collection_mutex);
+  for (collection::iterator pos = m_collection.begin();
+       pos != m_collection.end(); ++pos) {
+    if (*pos == wp) {
+      m_collection.erase(pos);
+      return true;
+    }
+  }
+  return false;
+}
+
+WatchpointSP WatchpointCollection::GetByIndex(size_t i) {
+  std::lock_guard<std::mutex> guard(m_collection_mutex);
+  if (i < m_collection.size())
+    return m_collection[i];
+  return {};
+}
+
+const WatchpointSP WatchpointCollection::GetByIndex(size_t i) const {
+  std::lock_guard<std::mutex> guard(m_collection_mutex);
+  if (i < m_collection.size())
+    return m_collection[i];
+  return {};
+}
+
+WatchpointCollection &
+WatchpointCollection::operator=(const WatchpointCollection &rhs) {
+  if (this != &rhs) {
+    std::lock(m_collection_mutex, rhs.m_collection_mutex);
+    std::lock_guard<std::mutex> lhs_guard(m_collection_mutex, std::adopt_lock);
+    std::lock_guard<std::mutex> rhs_guard(rhs.m_collection_mutex,
+                                          std::adopt_lock);
----------------
bulbazord wrote:

You can use `std::scoped_lock` for this now that we're using C++17! 😄 

https://github.com/llvm/llvm-project/pull/68845
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to