b37814204f
* get image returns optional<Mat> instead of unique_ptr<Mat> * introduce complexity * rename image load function * add example for a basic reader for binary image files * fix windows build? * add a status bar underneath the menu bar * use status bar in custom_0 example app * clang formats * packing w/ pragma push * add "Save As" functions to image views * resize over reserve * rm local override uri * add simple thread pool * rename to simple_thread_pool * get rid of useless renderlib * document version inc * extract hardcoded values to in-header * clang format patch * clone registered image in custom_0 * document binary-file header * minor fixes * clang format * rm unused render cmake
48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
#include "simple_thread_pool.hpp"
|
|
|
|
#include <functional>
|
|
#include <mutex>
|
|
|
|
using namespace pixelarium::utils;
|
|
|
|
simple_thread_pool::simple_thread_pool(size_t num_threads)
|
|
{
|
|
for (size_t i{0}; i < num_threads; ++i)
|
|
{
|
|
workers_.emplace_back(
|
|
[this]()
|
|
{
|
|
while (true)
|
|
{
|
|
std::function<void()> job;
|
|
{
|
|
std::unique_lock<std::mutex> lck(thread_mutex_);
|
|
|
|
cv_.wait(lck, [this]() -> bool { return shutdown_ || !task_queue_.empty(); });
|
|
|
|
if (shutdown_ && task_queue_.empty()) return;
|
|
|
|
job = std::move(task_queue_.front());
|
|
task_queue_.pop();
|
|
}
|
|
|
|
job();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
simple_thread_pool::~simple_thread_pool()
|
|
{
|
|
{
|
|
std::unique_lock<std::mutex> lck(thread_mutex_);
|
|
shutdown_ = true;
|
|
}
|
|
|
|
cv_.notify_all();
|
|
for (auto& th : workers_)
|
|
{
|
|
th.join();
|
|
}
|
|
}
|