1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Update ThreadPool.hpp

This commit is contained in:
Sandu Liviu Catalin 2022-09-15 23:03:50 +03:00
parent 475a428366
commit c9fb257f48

View File

@ -80,7 +80,7 @@ struct ThreadPoolItem
/* --------------------------------------------------------------------------------------------
* Invoked in main thread by the thread pool after the task was completed.
* If it returns true then it will be put back into the queue to be processed again.
* If the boolean parameter is trye then the thread-pool is in the process of shutting down.
* If the boolean parameter is true then the thread-pool is in the process of shutting down.
*/
SQMOD_NODISCARD virtual bool OnCompleted(bool SQ_UNUSED_ARG(stop)) { return false; }
@ -110,13 +110,13 @@ private:
* Destructor.
*/
~ThreadPool();
public:
// --------------------------------------------------------------------------------------------
using Item = std::unique_ptr< ThreadPoolItem >; // Owning pointer of an item.
private:
// --------------------------------------------------------------------------------------------
using Pool = std::vector< std::thread >; // Worker container.
using Item = std::unique_ptr< ThreadPoolItem >; // Owning pointer of an item.
// --------------------------------------------------------------------------------------------
using Finished = moodycamel::ConcurrentQueue< Item >; // Finished items.
// --------------------------------------------------------------------------------------------
@ -190,6 +190,14 @@ public:
Enqueue(Item{item});
}
/* --------------------------------------------------------------------------------------------
* Queue an item to be processed. Will take ownership of the given pointer!
*/
template < class T > void CastEnqueue(std::unique_ptr< T > && item)
{
Enqueue(Item{std::forward< std::unique_ptr< T > >(item)});
}
/* --------------------------------------------------------------------------------------------
* Queue an item to be processed. Will take ownership of the given pointer!
*/