impr: Calculate hashes in a background thread

This commit is contained in:
WerWolv
2025-12-04 20:57:06 +01:00
parent ab54acb176
commit f2e8d402dd
5 changed files with 143 additions and 64 deletions

View File

@@ -38,24 +38,14 @@ EXPORT_MODULE namespace hex {
[[nodiscard]] const Hash *getType() const { return m_type; }
[[nodiscard]] const std::string& getName() const { return m_name; }
const std::vector<u8>& get(const Region& region, prv::Provider *provider) {
if (m_cache.empty()) {
m_cache = m_callback(region, provider);
}
return m_cache;
}
void reset() {
m_cache.clear();
std::vector<u8> get(const Region& region, prv::Provider *provider) const {
return m_callback(region, provider);
}
private:
Hash *m_type;
std::string m_name;
Callback m_callback;
std::vector<u8> m_cache;
};
virtual void draw() { }

View File

@@ -70,6 +70,8 @@ EXPORT_MODULE namespace hex {
[[nodiscard]] u64 getValue() const;
[[nodiscard]] u64 getMaxValue() const;
void wait() const;
private:
void finish();
void interruption();
@@ -87,9 +89,9 @@ EXPORT_MODULE namespace hex {
std::atomic<bool> m_background = true;
std::atomic<bool> m_blocking = false;
std::atomic<bool> m_interrupted = false;
std::atomic<bool> m_finished = false;
std::atomic<bool> m_hadException = false;
std::atomic_flag m_interrupted = false;
std::atomic_flag m_finished = false;
std::atomic_flag m_hadException = false;
std::string m_exceptionMessage;
struct TaskInterruptor { virtual ~TaskInterruptor() = default; };
@@ -114,6 +116,7 @@ EXPORT_MODULE namespace hex {
[[nodiscard]] u32 getProgress() const;
void interrupt() const;
void wait() const;
private:
std::weak_ptr<Task> m_task;
};