#include "lldb/Utility/Status.h"
#include "llvm/Support/JSON.h"
#include <map>
+#include <mutex>
#include <optional>
#include <vector>
llvm::json::Value ToJSON();
- bool IsEmpty() const { return m_pairs.empty(); }
+ bool IsEmpty() const {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
+ return m_pairs.empty();
+ }
- size_t GetSize() const { return m_pairs.size(); }
+ size_t GetSize() const {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
+ return m_pairs.size();
+ }
bool GetPathsAtIndex(uint32_t idx, ConstString &path,
ConstString &new_path) const;
uint32_t FindIndexForPath(llvm::StringRef path) const;
- uint32_t GetModificationID() const { return m_mod_id; }
+ uint32_t GetModificationID() const {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
+ return m_mod_id;
+ }
protected:
+ mutable std::recursive_mutex m_mutex;
typedef std::pair<ConstString, ConstString> pair;
typedef std::vector<pair> collection;
typedef collection::iterator iterator;
const PathMappingList &PathMappingList::operator=(const PathMappingList &rhs) {
if (this != &rhs) {
+ std::scoped_lock locks(m_mutex, rhs.m_mutex);
m_pairs = rhs.m_pairs;
m_callback = nullptr;
m_callback_baton = nullptr;
void PathMappingList::Append(llvm::StringRef path, llvm::StringRef replacement,
bool notify) {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
++m_mod_id;
m_pairs.emplace_back(pair(NormalizePath(path), NormalizePath(replacement)));
if (notify && m_callback)
}
void PathMappingList::Append(const PathMappingList &rhs, bool notify) {
+ std::scoped_lock locks(m_mutex, rhs.m_mutex);
++m_mod_id;
if (!rhs.m_pairs.empty()) {
const_iterator pos, end = rhs.m_pairs.end();
llvm::StringRef replacement, bool notify) {
auto normalized_path = NormalizePath(path);
auto normalized_replacement = NormalizePath(replacement);
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
for (const auto &pair : m_pairs) {
if (pair.first.GetStringRef().equals(normalized_path) &&
pair.second.GetStringRef().equals(normalized_replacement))
void PathMappingList::Insert(llvm::StringRef path, llvm::StringRef replacement,
uint32_t index, bool notify) {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
++m_mod_id;
iterator insert_iter;
if (index >= m_pairs.size())
bool PathMappingList::Replace(llvm::StringRef path, llvm::StringRef replacement,
uint32_t index, bool notify) {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (index >= m_pairs.size())
return false;
++m_mod_id;
}
bool PathMappingList::Remove(size_t index, bool notify) {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (index >= m_pairs.size())
return false;
// For clients which do not need the pair index dumped, pass a pair_index >= 0
// to only dump the indicated pair.
void PathMappingList::Dump(Stream *s, int pair_index) {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
unsigned int numPairs = m_pairs.size();
if (pair_index < 0) {
llvm::json::Value PathMappingList::ToJSON() {
llvm::json::Array entries;
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
for (const auto &pair : m_pairs) {
llvm::json::Array entry{pair.first.GetStringRef().str(),
pair.second.GetStringRef().str()};
}
void PathMappingList::Clear(bool notify) {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (!m_pairs.empty())
++m_mod_id;
m_pairs.clear();
std::optional<FileSpec> PathMappingList::RemapPath(llvm::StringRef mapping_path,
bool only_if_exists) const {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (m_pairs.empty() || mapping_path.empty())
return {};
LazyBool path_is_relative = eLazyBoolCalculate;
PathMappingList::ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const {
std::string path = file.GetPath();
llvm::StringRef path_ref(path);
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
for (const auto &it : m_pairs) {
llvm::StringRef removed_prefix = it.second.GetStringRef();
if (!path_ref.consume_front(it.second.GetStringRef()))
bool PathMappingList::Replace(llvm::StringRef path, llvm::StringRef new_path,
bool notify) {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
uint32_t idx = FindIndexForPath(path);
if (idx < m_pairs.size()) {
++m_mod_id;
}
bool PathMappingList::Remove(ConstString path, bool notify) {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
iterator pos = FindIteratorForPath(path);
if (pos != m_pairs.end()) {
++m_mod_id;
PathMappingList::const_iterator
PathMappingList::FindIteratorForPath(ConstString path) const {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
const_iterator pos;
const_iterator begin = m_pairs.begin();
const_iterator end = m_pairs.end();
PathMappingList::iterator
PathMappingList::FindIteratorForPath(ConstString path) {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
iterator pos;
iterator begin = m_pairs.begin();
iterator end = m_pairs.end();
bool PathMappingList::GetPathsAtIndex(uint32_t idx, ConstString &path,
ConstString &new_path) const {
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (idx < m_pairs.size()) {
path = m_pairs[idx].first;
new_path = m_pairs[idx].second;
uint32_t PathMappingList::FindIndexForPath(llvm::StringRef orig_path) const {
const ConstString path = ConstString(NormalizePath(orig_path));
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
const_iterator pos;
const_iterator begin = m_pairs.begin();
const_iterator end = m_pairs.end();