Update prebuilt Clang to r416183b from Android.
https://android.googlesource.com/platform/prebuilts/clang/host/
linux-x86/+/06a71ddac05c22edb2d10b590e1769b3f8619bef
clang 12.0.5 (based on r416183b) from build 7284624.
Change-Id: I277a316abcf47307562d8b748b84870f31a72866
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
diff --git a/linux-x64/clang/include/lldb/Utility/SharedCluster.h b/linux-x64/clang/include/lldb/Utility/SharedCluster.h
index 71bbb33..375c1c1 100644
--- a/linux-x64/clang/include/lldb/Utility/SharedCluster.h
+++ b/linux-x64/clang/include/lldb/Utility/SharedCluster.h
@@ -6,90 +6,54 @@
//
//===----------------------------------------------------------------------===//
-#ifndef utility_SharedCluster_h_
-#define utility_SharedCluster_h_
+#ifndef LLDB_UTILITY_SHAREDCLUSTER_H
+#define LLDB_UTILITY_SHAREDCLUSTER_H
#include "lldb/Utility/LLDBAssert.h"
-#include "lldb/Utility/SharingPtr.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/SmallPtrSet.h"
-
+#include <memory>
#include <mutex>
namespace lldb_private {
-namespace imp {
-template <typename T>
-class shared_ptr_refcount : public lldb_private::imp::shared_count {
+template <class T>
+class ClusterManager : public std::enable_shared_from_this<ClusterManager<T>> {
public:
- template <class Y>
- shared_ptr_refcount(Y *in) : shared_count(0), manager(in) {}
-
- shared_ptr_refcount() : shared_count(0) {}
-
- ~shared_ptr_refcount() override {}
-
- void on_zero_shared() override { manager->DecrementRefCount(); }
-
-private:
- T *manager;
-};
-
-} // namespace imp
-
-template <class T> class ClusterManager {
-public:
- ClusterManager() : m_objects(), m_external_ref(0), m_mutex() {}
+ static std::shared_ptr<ClusterManager> Create() {
+ return std::shared_ptr<ClusterManager>(new ClusterManager());
+ }
~ClusterManager() {
- for (typename llvm::SmallPtrSet<T *, 16>::iterator pos = m_objects.begin(),
- end = m_objects.end();
- pos != end; ++pos) {
- T *object = *pos;
- delete object;
- }
-
- // Decrement refcount should have been called on this ClusterManager, and
- // it should have locked the mutex, now we will unlock it before we destroy
- // it...
- m_mutex.unlock();
+ for (T *obj : m_objects)
+ delete obj;
}
void ManageObject(T *new_object) {
std::lock_guard<std::mutex> guard(m_mutex);
- m_objects.insert(new_object);
+ assert(!llvm::is_contained(m_objects, new_object) &&
+ "ManageObject called twice for the same object?");
+ m_objects.push_back(new_object);
}
- typename lldb_private::SharingPtr<T> GetSharedPointer(T *desired_object) {
- {
- std::lock_guard<std::mutex> guard(m_mutex);
- m_external_ref++;
- if (0 == m_objects.count(desired_object)) {
- lldbassert(false && "object not found in shared cluster when expected");
- desired_object = nullptr;
- }
+ std::shared_ptr<T> GetSharedPointer(T *desired_object) {
+ std::lock_guard<std::mutex> guard(m_mutex);
+ auto this_sp = this->shared_from_this();
+ if (!llvm::is_contained(m_objects, desired_object)) {
+ lldbassert(false && "object not found in shared cluster when expected");
+ desired_object = nullptr;
}
- return typename lldb_private::SharingPtr<T>(
- desired_object, new imp::shared_ptr_refcount<ClusterManager>(this));
+ return {std::move(this_sp), desired_object};
}
private:
- void DecrementRefCount() {
- m_mutex.lock();
- m_external_ref--;
- if (m_external_ref == 0)
- delete this;
- else
- m_mutex.unlock();
- }
+ ClusterManager() : m_objects(), m_mutex() {}
- friend class imp::shared_ptr_refcount<ClusterManager>;
-
- llvm::SmallPtrSet<T *, 16> m_objects;
- int m_external_ref;
+ llvm::SmallVector<T *, 16> m_objects;
std::mutex m_mutex;
};
} // namespace lldb_private
-#endif // utility_SharedCluster_h_
+#endif // LLDB_UTILITY_SHAREDCLUSTER_H