1
0
mirror of synced 2024-12-02 11:17:19 +01:00
ImHex/lib/libimhex/source/api/task.cpp
WerWolv 1991afb87b
sys: Get rid of SharedData struct and cleanup code structure (#411)
* sys: Initial refactoring of the SharedData class

* sys/pattern: More refactoring, make every provider have its own patterns

* sys: Finished up refactoring. No more SharedData!

* sys: Fixed compile on Unix

* tests: Fixed unit tests

* sys: Moved view and lang files

* pattern: Added assignment operator support to for loops

* tests: Fixed compile issue
2022-02-01 18:09:40 +01:00

56 lines
1.3 KiB
C++

#include <hex/api/task.hpp>
#include <hex/api/localization.hpp>
namespace hex {
std::list<Task *> Task::s_runningTasks;
std::mutex Task::s_taskMutex;
Task::Task(const std::string &unlocalizedName, u64 maxValue) : m_name(LangEntry(unlocalizedName)), m_maxValue(maxValue), m_currValue(0) {
std::scoped_lock lock(Task::s_taskMutex);
Task::s_runningTasks.push_back(this);
}
Task::~Task() {
this->finish();
}
void Task::finish() {
std::scoped_lock lock(Task::s_taskMutex);
Task::s_runningTasks.remove(this);
}
void Task::setMaxValue(u64 maxValue) {
this->m_maxValue = maxValue;
}
void Task::update(u64 currValue) {
if (this->m_currValue < this->m_maxValue)
this->m_currValue = currValue;
}
double Task::getProgress() const {
if (this->m_maxValue == 0)
return 100;
return static_cast<double>(this->m_currValue) / static_cast<double>(this->m_maxValue);
}
bool Task::isPending() const {
return this->m_maxValue == 0;
}
const std::string &Task::getName() const {
return this->m_name;
}
size_t Task::getRunningTaskCount() {
std::scoped_lock lock(Task::s_taskMutex);
return Task::s_runningTasks.size();
}
}