fixed design store threading beharior (actual designs still not fully implemented)
This commit is contained in:
parent
20a4370273
commit
2001e0890a
3 changed files with 28 additions and 5 deletions
|
|
@ -44,7 +44,7 @@ class Downloader {
|
|||
|
||||
void thread_run();
|
||||
bool fetch_tasks(size_t n);
|
||||
bool fetch_design(const db::uuid_t& id);
|
||||
bool fetch_design(const db::uuid_t& id, std::string& design);
|
||||
void reopen_task(const db::uuid_t& id);
|
||||
|
||||
std::unique_ptr<std::thread> downloader_thread;
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ void Downloader::thread_run() {
|
|||
auto task = this->interface.pop_fresh(empty);
|
||||
if (empty) continue;
|
||||
this->reopen_task(task->id);
|
||||
this->interface.decrement_design(task->design);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,13 +94,18 @@ bool Downloader::fetch_tasks(size_t n) {
|
|||
|
||||
// see if we already have the desing locally; if not, load it
|
||||
if (!this->interface.increment_design(task->design)) {
|
||||
|
||||
DEBUG_PRINT("Fetching new design with ID " + db::to_string(task->design));
|
||||
std::string design;
|
||||
|
||||
// if we could not load the design, reopen it in the database
|
||||
if (!this->fetch_design(task->design)) {
|
||||
if (!this->fetch_design(task->design, design)) {
|
||||
std::cerr << "Error: Could not load design for task " << task->id << ", reopening it." << std::endl;
|
||||
this->reopen_task(task->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
this->interface.store_design(task->design, design);
|
||||
}
|
||||
|
||||
// push the task to the list of open tasks
|
||||
|
|
@ -110,7 +116,8 @@ bool Downloader::fetch_tasks(size_t n) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Downloader::fetch_design(const db::uuid_t& id) {
|
||||
bool Downloader::fetch_design(const db::uuid_t& id, std::string& design) {
|
||||
design = "test design";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,32 +128,44 @@ std::unique_ptr<OutputType> TaskInterface::pop_finished(bool& empty) {
|
|||
|
||||
bool TaskInterface::increment_design(const db::uuid_t& id) {
|
||||
std::lock_guard<std::mutex> lock (this->designs_mutex);
|
||||
DEBUG_PRINT("Looking for design with ID " + db::to_string(id));
|
||||
|
||||
// make sure the requested design is in the list of available designs
|
||||
if (this->designs.find(id) == this->designs.end()) return false;
|
||||
if (this->designs.find(id) == this->designs.end()) {
|
||||
DEBUG_PRINT("Design not found.");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::pair<size_t, std::string>& design_entry = designs[id];
|
||||
|
||||
// if so, increment its reference counters
|
||||
++design_entry.first;
|
||||
|
||||
DEBUG_PRINT("Design found. Incrementing reference counter. New counter is " + std::to_string(design_entry.first));
|
||||
return true;
|
||||
}
|
||||
|
||||
void TaskInterface::decrement_design(const db::uuid_t& id) {
|
||||
std::lock_guard<std::mutex> lock (this->designs_mutex);
|
||||
DEBUG_PRINT("Looking to decrement design with ID " + db::to_string(id));
|
||||
|
||||
// make sure the requested design is in the list of available designs
|
||||
if (this->designs.find(id) == this->designs.end()) return;
|
||||
if (this->designs.find(id) == this->designs.end()) {
|
||||
DEBUG_PRINT("Could not find design. Not decrementing.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::pair<size_t, std::string>& design_entry = designs[id];
|
||||
|
||||
// if so, decrement its reference counters
|
||||
--design_entry.first;
|
||||
|
||||
DEBUG_PRINT("Design found. Decrementing reference counter. New counter is " + std::to_string(design_entry.first));
|
||||
|
||||
// if the reference counter hit 0, erase the design entry from the list
|
||||
// of available designs
|
||||
if (design_entry.first == 0) {
|
||||
DEBUG_PRINT("Erasing design from store.");
|
||||
this->designs.erase(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -173,9 +185,13 @@ std::string TaskInterface::get_design(const db::uuid_t& id) {
|
|||
void TaskInterface::store_design(const db::uuid_t& id, std::string& design) {
|
||||
std::lock_guard<std::mutex> lock (this->designs_mutex);
|
||||
|
||||
DEBUG_PRINT("Henlo Storing new design with ID " + db::to_string(id));
|
||||
std::cerr << "This should really be visible here" << std::endl;
|
||||
|
||||
// make sure the design isn't already in the list of design entries
|
||||
// if it is, just increment its reference counter
|
||||
if (this->designs.find(id) != this->designs.end()) {
|
||||
DEBUG_PRINT("Design is already in here, incrementing reference counter instead.");
|
||||
++(this->designs[id]).first;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue