Trying out generic thread pool
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
target_sources(SeeleEngine
|
||||
PRIVATE
|
||||
EngineTypes.h
|
||||
MinimalEngine.h
|
||||
MinimalEngine.cpp
|
||||
main.cpp)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "ThreadPool.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
static ThreadPool gThreadPool;
|
||||
|
||||
Job JobPromise::get_return_object() noexcept {
|
||||
return Job { std::coroutine_handle<JobPromise>::from_promise(*this) };
|
||||
}
|
||||
|
||||
ThreadPool::ThreadPool(uint32 threadCount)
|
||||
: workers(threadCount)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static ThreadPool& getGlobalThreadPool()
|
||||
{
|
||||
return gThreadPool;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
#include <thread>
|
||||
#include <coroutine>
|
||||
#include "MinimalEngine.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
enum class JobStage
|
||||
{
|
||||
INPUT,
|
||||
GAMELOGIC,
|
||||
RENDER,
|
||||
DONT_CARE
|
||||
};
|
||||
struct [[nodiscard]] Job;
|
||||
struct JobPromise
|
||||
{
|
||||
Job get_return_object() noexcept;
|
||||
|
||||
std::suspend_never initial_suspend() const noexcept { return {}; }
|
||||
std::suspend_never final_suspend() const noexcept { return {}; }
|
||||
|
||||
void return_void() noexcept {}
|
||||
void unhandled_exception() noexcept {
|
||||
std::cerr << "Unhandled exception caught" << std::endl;
|
||||
exit(1);
|
||||
};
|
||||
};
|
||||
struct [[nodiscard]] Job
|
||||
{
|
||||
public:
|
||||
using promise_type = JobPromise;
|
||||
|
||||
explicit Job(std::coroutine_handle<task_promise> handle, JobStage stage = JobStage::DONT_CARE)
|
||||
: handle(handle)
|
||||
, stage(stage)
|
||||
{}
|
||||
~Job()
|
||||
{
|
||||
if(handle)
|
||||
{
|
||||
handle.destroy();
|
||||
}
|
||||
}
|
||||
private:
|
||||
std::coroutine_handle<JobPromise> handle;
|
||||
JobStage stage;
|
||||
};
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
public:
|
||||
ThreadPool(uint32 threadCount = std::thread::hardware_concurrency);
|
||||
virtual ~ThreadPool();
|
||||
void schedule(std::function<void()> function)
|
||||
{
|
||||
|
||||
}
|
||||
private:
|
||||
Array<std::thread> workers;
|
||||
void threadLoop();
|
||||
};
|
||||
static ThreadPool& getGlobalThreadPool();
|
||||
} // namespace Seele
|
||||
@@ -35,7 +35,7 @@ void RenderHierarchy::addElement(PElement addedElement)
|
||||
updates.add(new AddElementRenderHierarchyUpdate{
|
||||
addedElement.getHandle(),
|
||||
addedElement->getParent().getHandle()
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
void RenderHierarchy::removeElement(PElement elementToRemove)
|
||||
@@ -68,6 +68,6 @@ void RenderHierarchy::updateHierarchy()
|
||||
}
|
||||
for(auto update : localUpdates)
|
||||
{
|
||||
|
||||
update->apply(drawElements);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(Window)
|
||||
|
||||
// A view is a part of the window, which can be anything from a scene viewport to an inspector
|
||||
class View
|
||||
{
|
||||
|
||||
@@ -54,7 +54,7 @@ void Window::setFocused(PView view)
|
||||
}
|
||||
|
||||
|
||||
void Window::viewWorker(WindowView* windowView)
|
||||
void Window::viewWorker(WindowView* windowView)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user