More threadpool bs

This commit is contained in:
Dynamitos
2021-12-02 13:00:03 +01:00
parent 5fafdda770
commit 9e3a2446ce
37 changed files with 488 additions and 541 deletions
+9 -4
View File
@@ -1,4 +1,5 @@
#include "ThreadPool.h"
#include <memory_resource>
using namespace Seele;
@@ -6,6 +7,10 @@ Event::Event()
: flag(new std::atomic_bool())
{}
Event::Event(nullptr_t)
: flag(nullptr)
{}
Event::Event(const std::string& name)
: name(name)
, flag(new std::atomic_bool())
@@ -32,7 +37,7 @@ ThreadPool::ThreadPool(uint32 threadCount)
running.store(true);
for(uint32 i = 0; i < threadCount; ++i)
{
workers[i] = std::thread(&ThreadPool::threadLoop, this, i == 0);
workers[i] = std::thread(&ThreadPool::threadLoop, this, false);
}
}
@@ -58,13 +63,13 @@ void ThreadPool::addJob(MainJob&& job)
mainJobs.add(std::move(job));
mainJobCV.notify_one();
}
void ThreadPool::enqueueWaiting(Event& event, Job job)
void ThreadPool::enqueueWaiting(Event& event, Job&& job)
{
//std::cout << job.id << " waiting for event " << event.name << std::endl;
std::unique_lock lock(waitingLock);
waitingJobs[event].add(std::move(job));
}
void ThreadPool::enqueueWaiting(Event& event, MainJob job)
void ThreadPool::enqueueWaiting(Event& event, MainJob&& job)
{
//std::cout << job.id << " main waiting for event " << event.name << std::endl;
std::unique_lock lock(waitingMainLock);
@@ -143,7 +148,7 @@ void ThreadPool::threadLoop(const bool mainThread)
job.resume();
if(job.done())
{
job.signal();
job.raise();
}
}
}