fix: Race condition with data inspector
This commit is contained in:
parent
7bb9e7ee82
commit
7f2c60b0d7
@ -29,7 +29,6 @@ namespace hex {
|
||||
void update(u64 value = 0);
|
||||
void setMaxValue(u64 value);
|
||||
|
||||
[[nodiscard]] bool isRunning() const;
|
||||
[[nodiscard]] bool isBackgroundTask() const;
|
||||
[[nodiscard]] bool isFinished() const;
|
||||
[[nodiscard]] bool hadException() const;
|
||||
@ -45,8 +44,6 @@ namespace hex {
|
||||
|
||||
void setInterruptCallback(std::function<void()> callback);
|
||||
|
||||
void setRunning(bool running);
|
||||
|
||||
private:
|
||||
void finish();
|
||||
void interruption();
|
||||
@ -60,7 +57,6 @@ namespace hex {
|
||||
std::function<void()> m_interruptCallback;
|
||||
std::function<void(Task &)> m_function;
|
||||
|
||||
std::atomic<bool> m_running = false;
|
||||
std::atomic<bool> m_shouldInterrupt = false;
|
||||
std::atomic<bool> m_background = true;
|
||||
|
||||
|
@ -36,7 +36,6 @@ namespace hex {
|
||||
this->m_hadException = bool(other.m_hadException);
|
||||
this->m_interrupted = bool(other.m_interrupted);
|
||||
this->m_shouldInterrupt = bool(other.m_shouldInterrupt);
|
||||
this->m_running = bool(other.m_running);
|
||||
}
|
||||
|
||||
Task::~Task() {
|
||||
@ -67,10 +66,6 @@ namespace hex {
|
||||
this->m_interruptCallback = std::move(callback);
|
||||
}
|
||||
|
||||
void Task::setRunning(bool running) {
|
||||
this->m_running = running;
|
||||
}
|
||||
|
||||
bool Task::isBackgroundTask() const {
|
||||
return this->m_background;
|
||||
}
|
||||
@ -91,10 +86,6 @@ namespace hex {
|
||||
this->m_hadException = false;
|
||||
}
|
||||
|
||||
bool Task::isRunning() const {
|
||||
return this->m_running;
|
||||
}
|
||||
|
||||
std::string Task::getExceptionMessage() const {
|
||||
std::scoped_lock lock(this->m_mutex);
|
||||
|
||||
@ -130,20 +121,35 @@ namespace hex {
|
||||
|
||||
|
||||
bool TaskHolder::isRunning() const {
|
||||
return !m_task.expired() && !m_task.lock()->isFinished();
|
||||
if (this->m_task.expired())
|
||||
return false;
|
||||
|
||||
auto task = this->m_task.lock();
|
||||
return !task->isFinished();
|
||||
}
|
||||
|
||||
bool TaskHolder::hadException() const {
|
||||
return m_task.expired() || m_task.lock()->hadException();
|
||||
if (this->m_task.expired())
|
||||
return false;
|
||||
|
||||
auto task = this->m_task.lock();
|
||||
return !task->hadException();
|
||||
}
|
||||
|
||||
bool TaskHolder::wasInterrupted() const {
|
||||
return m_task.expired() || m_task.lock()->wasInterrupted();
|
||||
if (this->m_task.expired())
|
||||
return false;
|
||||
|
||||
auto task = this->m_task.lock();
|
||||
return !task->wasInterrupted();
|
||||
}
|
||||
|
||||
void TaskHolder::interrupt() {
|
||||
if (!this->m_task.expired())
|
||||
this->m_task.lock()->interrupt();
|
||||
if (this->m_task.expired())
|
||||
return;
|
||||
|
||||
auto task = this->m_task.lock();
|
||||
task->interrupt();
|
||||
}
|
||||
|
||||
|
||||
@ -176,7 +182,7 @@ namespace hex {
|
||||
if (stopToken.stop_requested())
|
||||
break;
|
||||
|
||||
task = s_tasks.front();
|
||||
task = std::move(s_tasks.front());
|
||||
s_tasks.pop_front();
|
||||
}
|
||||
|
||||
|
@ -63,10 +63,10 @@ int main(int argc, char **argv, char **envp) {
|
||||
window.loop();
|
||||
} catch (const std::exception &e) {
|
||||
log::fatal("Exception thrown in main loop: {}", e.what());
|
||||
return EXIT_FAILURE;
|
||||
throw;
|
||||
} catch (...) {
|
||||
log::fatal("Unknown exception thrown in main loop!");
|
||||
return EXIT_FAILURE;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,11 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void ViewDataInspector::drawContent() {
|
||||
if (this->m_dataValid) {
|
||||
this->m_dataValid = false;
|
||||
this->m_cachedData = std::move(this->m_workData);
|
||||
}
|
||||
|
||||
if (this->m_shouldInvalidate && !this->m_updateTask.isRunning()) {
|
||||
this->m_shouldInvalidate = false;
|
||||
|
||||
@ -133,11 +138,6 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
}
|
||||
|
||||
if (this->m_dataValid) {
|
||||
this->m_dataValid = false;
|
||||
this->m_cachedData = this->m_workData;
|
||||
}
|
||||
|
||||
if (ImGui::Begin(View::toWindowName("hex.builtin.view.data_inspector.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user