2021-10-12 14:20:30 +02:00
|
|
|
#include "ThreadPool.h"
|
|
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
2021-10-23 00:22:35 +02:00
|
|
|
|
|
|
|
|
void Event::await_suspend(std::coroutine_handle<JobPromise> h)
|
|
|
|
|
{
|
|
|
|
|
getGlobalThreadPool().addJob(Job(h));
|
|
|
|
|
}
|
2021-10-12 14:20:30 +02:00
|
|
|
|
|
|
|
|
Job JobPromise::get_return_object() noexcept {
|
|
|
|
|
return Job { std::coroutine_handle<JobPromise>::from_promise(*this) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ThreadPool::ThreadPool(uint32 threadCount)
|
|
|
|
|
: workers(threadCount)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-23 00:22:35 +02:00
|
|
|
ThreadPool::~ThreadPool()
|
2021-10-12 14:20:30 +02:00
|
|
|
{
|
2021-10-23 00:22:35 +02:00
|
|
|
for(auto& thread : workers)
|
|
|
|
|
{
|
|
|
|
|
thread.join();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ThreadPool& Seele::getGlobalThreadPool()
|
|
|
|
|
{
|
|
|
|
|
static ThreadPool threadPool;
|
|
|
|
|
return threadPool;
|
2021-10-12 14:20:30 +02:00
|
|
|
}
|