augusto2112 updated this revision to Diff 547284.
augusto2112 added a comment.
Addressed comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157041/new/
https://reviews.llvm.org/D157041
Files:
lldb/include/lldb/Interpreter/OptionValue.h
lldb/source/Interpreter/OptionValue.cpp
Index: lldb/source/Interpreter/OptionValue.cpp
===================================================================
--- lldb/source/Interpreter/OptionValue.cpp
+++ lldb/source/Interpreter/OptionValue.cpp
@@ -15,6 +15,26 @@
using namespace lldb;
using namespace lldb_private;
+
+OptionValue::OptionValue(const OptionValue &other) {
+ std::lock_guard<std::mutex> lock(other.m_mutex);
+
+ m_parent_wp = other.m_parent_wp;
+ m_callback = other.m_callback;
+ m_value_was_set = other.m_value_was_set;
+
+}
+
+OptionValue& OptionValue::operator=(const OptionValue &other) {
+ std::scoped_lock lock(m_mutex, other.m_mutex);
+
+ m_parent_wp = other.m_parent_wp;
+ m_callback = other.m_callback;
+ m_value_was_set = other.m_value_was_set;
+
+ return *this;
+}
+
Status OptionValue::SetSubValue(const ExecutionContext *exe_ctx,
VarSetOperationType op, llvm::StringRef name,
llvm::StringRef value) {
@@ -216,6 +236,7 @@
}
OptionValueString *OptionValue::GetAsString() {
+
if (GetType() == OptionValue::eTypeString)
return static_cast<OptionValueString *>(this);
return nullptr;
@@ -252,12 +273,14 @@
}
std::optional<bool> OptionValue::GetBooleanValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueBoolean *option_value = GetAsBoolean())
return option_value->GetCurrentValue();
return {};
}
bool OptionValue::SetBooleanValue(bool new_value) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueBoolean *option_value = GetAsBoolean()) {
option_value->SetCurrentValue(new_value);
return true;
@@ -266,12 +289,14 @@
}
std::optional<char> OptionValue::GetCharValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueChar *option_value = GetAsChar())
return option_value->GetCurrentValue();
return {};
}
bool OptionValue::SetCharValue(char new_value) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueChar *option_value = GetAsChar()) {
option_value->SetCurrentValue(new_value);
return true;
@@ -280,12 +305,14 @@
}
std::optional<int64_t> OptionValue::GetEnumerationValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueEnumeration *option_value = GetAsEnumeration())
return option_value->GetCurrentValue();
return {};
}
bool OptionValue::SetEnumerationValue(int64_t value) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueEnumeration *option_value = GetAsEnumeration()) {
option_value->SetCurrentValue(value);
return true;
@@ -294,12 +321,14 @@
}
std::optional<FileSpec> OptionValue::GetFileSpecValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueFileSpec *option_value = GetAsFileSpec())
return option_value->GetCurrentValue();
return {};
}
bool OptionValue::SetFileSpecValue(FileSpec file_spec) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueFileSpec *option_value = GetAsFileSpec()) {
option_value->SetCurrentValue(file_spec, false);
return true;
@@ -308,6 +337,7 @@
}
bool OptionValue::AppendFileSpecValue(FileSpec file_spec) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueFileSpecList *option_value = GetAsFileSpecList()) {
option_value->AppendCurrentValue(file_spec);
return true;
@@ -316,18 +346,21 @@
}
std::optional<FileSpecList> OptionValue::GetFileSpecListValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueFileSpecList *option_value = GetAsFileSpecList())
return option_value->GetCurrentValue();
return {};
}
std::optional<lldb::Format> OptionValue::GetFormatValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueFormat *option_value = GetAsFormat())
return option_value->GetCurrentValue();
return {};
}
bool OptionValue::SetFormatValue(lldb::Format new_value) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueFormat *option_value = GetAsFormat()) {
option_value->SetCurrentValue(new_value);
return true;
@@ -336,12 +369,14 @@
}
std::optional<lldb::LanguageType> OptionValue::GetLanguageValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueLanguage *option_value = GetAsLanguage())
return option_value->GetCurrentValue();
return {};
}
bool OptionValue::SetLanguageValue(lldb::LanguageType new_language) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueLanguage *option_value = GetAsLanguage()) {
option_value->SetCurrentValue(new_language);
return true;
@@ -350,24 +385,30 @@
}
const FormatEntity::Entry *OptionValue::GetFormatEntity() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
+
if (const OptionValueFormatEntity *option_value = GetAsFormatEntity())
return &option_value->GetCurrentValue();
return nullptr;
}
const RegularExpression *OptionValue::GetRegexValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
+
if (const OptionValueRegex *option_value = GetAsRegex())
return option_value->GetCurrentValue();
return nullptr;
}
std::optional<int64_t> OptionValue::GetSInt64Value() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueSInt64 *option_value = GetAsSInt64())
return option_value->GetCurrentValue();
return {};
}
bool OptionValue::SetSInt64Value(int64_t new_value) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueSInt64 *option_value = GetAsSInt64()) {
option_value->SetCurrentValue(new_value);
return true;
@@ -376,12 +417,14 @@
}
std::optional<llvm::StringRef> OptionValue::GetStringValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueString *option_value = GetAsString())
return option_value->GetCurrentValueAsRef();
return {};
}
bool OptionValue::SetStringValue(llvm::StringRef new_value) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueString *option_value = GetAsString()) {
option_value->SetCurrentValue(new_value);
return true;
@@ -390,12 +433,14 @@
}
std::optional<uint64_t> OptionValue::GetUInt64Value() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueUInt64 *option_value = GetAsUInt64())
return option_value->GetCurrentValue();
return {};
}
bool OptionValue::SetUInt64Value(uint64_t new_value) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueUInt64 *option_value = GetAsUInt64()) {
option_value->SetCurrentValue(new_value);
return true;
@@ -404,12 +449,14 @@
}
std::optional<UUID> OptionValue::GetUUIDValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueUUID *option_value = GetAsUUID())
return option_value->GetCurrentValue();
return {};
}
bool OptionValue::SetUUIDValue(const UUID &uuid) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueUUID *option_value = GetAsUUID()) {
option_value->SetCurrentValue(uuid);
return true;
@@ -418,12 +465,14 @@
}
std::optional<ArchSpec> OptionValue::GetArchSpecValue() const {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (const OptionValueArch *option_value = GetAsArch())
return option_value->GetCurrentValue();
return {};
}
bool OptionValue::SetArchSpecValue(ArchSpec arch_spec) {
+ std::lock_guard<std::mutex> lock(m_mutex);
if (OptionValueArch *option_value = GetAsArch()) {
option_value->SetCurrentValue(arch_spec, false);
return true;
@@ -546,6 +595,7 @@
}
OptionValueSP OptionValue::DeepCopy(const OptionValueSP &new_parent) const {
+ std::lock_guard<std::mutex> lock(m_mutex);
auto clone = Clone();
clone->SetParent(new_parent);
return clone;
Index: lldb/include/lldb/Interpreter/OptionValue.h
===================================================================
--- lldb/include/lldb/Interpreter/OptionValue.h
+++ lldb/include/lldb/Interpreter/OptionValue.h
@@ -23,6 +23,7 @@
#include "lldb/lldb-private-enumerations.h"
#include "lldb/lldb-private-interfaces.h"
#include "llvm/Support/JSON.h"
+#include <mutex>
namespace lldb_private {
@@ -70,6 +71,10 @@
virtual ~OptionValue() = default;
+ OptionValue(const OptionValue &other);
+
+ OptionValue& operator=(const OptionValue &other);
+
// Subclasses should override these functions
virtual Type GetType() const = 0;
@@ -382,6 +387,8 @@
const FormatEntity::Entry *GetFormatEntity() const;
const RegularExpression *GetRegexValue() const;
+
+ mutable std::mutex m_mutex;
};
} // namespace lldb_private
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits