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:
parent
475a428366
commit
c9fb257f48
@ -80,7 +80,7 @@ struct ThreadPoolItem
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Invoked in main thread by the thread pool after the task was completed.
|
* 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 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; }
|
SQMOD_NODISCARD virtual bool OnCompleted(bool SQ_UNUSED_ARG(stop)) { return false; }
|
||||||
|
|
||||||
@ -110,13 +110,13 @@ private:
|
|||||||
* Destructor.
|
* Destructor.
|
||||||
*/
|
*/
|
||||||
~ThreadPool();
|
~ThreadPool();
|
||||||
|
public:
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
using Item = std::unique_ptr< ThreadPoolItem >; // Owning pointer of an item.
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
using Pool = std::vector< std::thread >; // Worker container.
|
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.
|
using Finished = moodycamel::ConcurrentQueue< Item >; // Finished items.
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
@ -190,6 +190,14 @@ public:
|
|||||||
Enqueue(Item{item});
|
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!
|
* Queue an item to be processed. Will take ownership of the given pointer!
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user