WorkQueueThread: provide name and function at same time

This commit is contained in:
Scott Mansell
2023-02-04 15:56:27 +13:00
parent 6594532f10
commit 7c4fcc30a3
11 changed files with 16 additions and 15 deletions

View File

@ -20,19 +20,20 @@ template <typename T>
class WorkQueueThread
{
public:
WorkQueueThread(std::string name) : m_thread_name(name){};
WorkQueueThread(std::function<void(T)> function, std::string name) : m_thread_name(name)
WorkQueueThread() = default;
WorkQueueThread(const std::string name, std::function<void(T)> function)
{
Reset(std::move(function));
Reset(std::move(name), std::move(function));
}
~WorkQueueThread() { Shutdown(); }
// Shuts the current work thread down (if any) and starts a new thread with the given function
// Note: Some consumers of this API push items to the queue before starting the thread.
void Reset(std::function<void(T)> function)
void Reset(const std::string& name, std::function<void(T)> function)
{
Shutdown();
std::lock_guard lg(m_lock);
m_thread_name = std::move(name);
m_shutdown = false;
m_function = std::move(function);
m_thread = std::thread(&WorkQueueThread::ThreadLoop, this);