From 9d70b894bfbd43b1c18ade84764f29a9e7ca0dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Wed, 21 Jun 2017 11:05:48 +0200 Subject: [PATCH] WX: Use std::future for checking disc integrity Simpler, and puts the call to CheckIntegrity right where it should be, instead of being hidden somewhere in a thread class. This also makes it more obvious what we're getting from the async task. Oh, and coincidentally, this fixes a random crash that could occur during the check. I'm not sure why. --- .../ISOProperties/FilesystemPanel.cpp | 36 +++++-------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp b/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp index e13b96db07..e431298ba6 100644 --- a/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp +++ b/Source/Core/DolphinWX/ISOProperties/FilesystemPanel.cpp @@ -5,7 +5,9 @@ #include "DolphinWX/ISOProperties/FilesystemPanel.h" #include +#include #include +#include #include #include @@ -41,25 +43,6 @@ public: std::unique_ptr filesystem; }; -class IntegrityCheckThread final : public wxThread -{ -public: - explicit IntegrityCheckThread(const DiscIO::Volume* volume, DiscIO::Partition partition) - : wxThread{wxTHREAD_JOINABLE}, m_volume{volume}, m_partition{partition} - { - Create(); - } - - ExitCode Entry() override - { - return reinterpret_cast(m_volume->CheckIntegrity(m_partition)); - } - -private: - const DiscIO::Volume* const m_volume; - const DiscIO::Partition m_partition; -}; - enum : int { ICON_DISC, @@ -326,18 +309,15 @@ void FilesystemPanel::OnCheckPartitionIntegrity(wxCommandEvent& WXUNUSED(event)) const auto selection = m_tree_ctrl->GetSelection(); WiiPartition* partition = static_cast(m_tree_ctrl->GetItemData(m_tree_ctrl->GetSelection())); - IntegrityCheckThread thread(m_opened_iso.get(), partition->filesystem->GetPartition()); - thread.Run(); + std::future is_valid = std::async(std::launch::async, [&] { + return m_opened_iso->CheckIntegrity(partition->filesystem->GetPartition()); + }); - while (thread.IsAlive()) - { + while (is_valid.wait_for(std::chrono::milliseconds(50)) != std::future_status::ready) dialog.Pulse(); - wxThread::Sleep(50); - } + dialog.Hide(); - dialog.Destroy(); - - if (thread.Wait()) + if (is_valid.get()) { wxMessageBox(_("Integrity check completed. No errors have been found."), _("Integrity check completed"), wxOK | wxICON_INFORMATION, this);