13 class ImageSavingThread
16 std::thread saving_thread;
17 std::vector<std::pair<Image, std::string>> queue;
18 std::mutex queue_mutex;
20 bool thread_should_run =
true;
21 void actual_saving_thread()
23 while (thread_should_run || queue.size() > 0)
26 bool has_images = queue.size() > 0;
33 queue.erase(queue.begin());
37 logger->info(
"Saving " + img.second);
38 save_img(img.first, img.second);
42 std::this_thread::sleep_for(std::chrono::seconds(1));
50 ImageSavingThread(
bool use_thread) : use_thread(use_thread)
53 saving_thread = std::thread(&ImageSavingThread::actual_saving_thread,
this);
58 thread_should_run =
false;
59 if (use_thread && saving_thread.joinable())
63 void push(
Image &img, std::string path)
68 queue.push_back({img, path});
73 logger->info(
"Saving " + path);