ThreadPool now working with no memory leaks

This commit is contained in:
Dynamitos
2022-02-14 16:29:26 +01:00
parent 6d48267ec2
commit 5268bb68e2
15 changed files with 287 additions and 97 deletions
+5 -1
View File
@@ -14,13 +14,17 @@ void MyComponent::start()
Job MyComponent::tick(float deltatime) const
{
writable++;
//std::cout << "MyComponent::tick" << std::endl;
++writable;
//std::cout << "MyComponent::tick finished" << std::endl;
otherComp->data = *writable;
co_return;
}
Job MyComponent::update()
{
//std::cout << "MyComponent::update" << std::endl;
writable.update();
//std::cout << "MyComponent::update finished" << std::endl;
co_return;
}
+1 -1
View File
@@ -13,7 +13,7 @@ public:
virtual Job update();
private:
Writable<PMyOtherComponent> otherComp;
Writable<uint32> writable = Writable<uint32>(0);
Writable<uint32> writable = 0;
uint32 notWritable = 10;
};
DECLARE_REF(MyComponent);
+14 -2
View File
@@ -43,18 +43,30 @@ void Scene::start()
Job Scene::beginUpdate(double deltaTime)
{
//std::cout << "Scene::beginUpdate" << std::endl;
Array<Job> jobs;
for(auto actor : rootActors)
{
co_await Job::all(actor->launchTick(static_cast<float>(deltaTime)));
jobs.addAll(actor->launchTick(static_cast<float>(deltaTime)));
}
co_await Job::all(jobs);
//std::cout << "Scene::beginUpdate finished waiting" << std::endl;
for(auto job : jobs)
{
assert(job.done());
}
}
Job Scene::commitUpdate()
{
//std::cout << "Scene::commitUpdate" << std::endl;
Array<Job> jobs;
for(auto actor : rootActors)
{
co_await Job::all(actor->launchUpdate());
jobs.addAll(actor->launchUpdate());
}
co_await Job::all(jobs);
//std::cout << "Scene::commitUpdate finished waiting" << std::endl;
}
void Scene::addActor(PActor actor)
+3 -3
View File
@@ -9,15 +9,15 @@ class Writable
public:
Writable()
{}
explicit Writable(T initialData)
Writable(T initialData)
: data(initialData)
, toBeWritten(initialData)
{}
Writable(const Writable& other) = delete;
Writable(Writable&& other) = default;
~Writable() = default;
Writable& operator=(const Writable& other) = delete;
Writable& operator=(Writable&& other) = default;
Writable& operator=(const Writable& other) const = delete;
Writable& operator=(Writable&& other) const = delete;
const Writable& operator=(const T& other) const
{
deferWrite(other);