Provisional multithreading framework

This commit is contained in:
Dynamitos
2021-03-31 12:18:16 +02:00
parent fb3c66cc4c
commit 28f0f88c03
37 changed files with 788 additions and 186 deletions
+1
View File
@@ -5,5 +5,6 @@ target_sources(Seele_unit_tests
EngineTest.cpp)
target_include_directories(Seele_unit_tests PUBLIC ./)
add_subdirectory(Containers/)
add_subdirectory(Fibers/)
add_subdirectory(Graphics/)
add_subdirectory(Math/)
+1 -1
View File
@@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(for_each)
map[6] = 4;
map[4] = 7;
int count = 0;
for(auto it = map.begin(); it != map.end(); ++it)
for(auto it : map)
{
count++;
}
+1 -1
View File
@@ -3,7 +3,7 @@
#include <boost/test/unit_test.hpp>
using namespace Seele;
BOOST_TEST_GLOBAL_FIXTURE(GlobalFixture);
BOOST_AUTO_TEST_SUITE(RefPtr)
struct TestStruct
+23 -1
View File
@@ -1 +1,23 @@
#pragma once
#pragma once
#include "Fibers/JobQueue.h"
namespace Seele
{
struct GlobalFixture
{
GlobalFixture()
{
}
~GlobalFixture()
{
}
void setup()
{
Fibers::JobQueue::initJobQueues();
}
void teardown()
{
Fibers::JobQueue::cleanupJobQueues();
}
};
};
+5
View File
@@ -0,0 +1,5 @@
target_sources(Seele_unit_tests
PRIVATE
../../../src/Engine/Fibers/JobQueue.cpp
../../../src/Engine/Fibers/Fibers.cpp
Fibers.cpp)
+61
View File
@@ -0,0 +1,61 @@
#include "EngineTest.h"
#include "MinimalEngine.h"
#include "Fibers/Fibers.h"
#include <coroutine>
#include <boost/test/unit_test.hpp>
using namespace Seele;
using namespace Seele::Fibers;
BOOST_AUTO_TEST_SUITE(Fibers_Suite)
FiberTask basicFiberSync1(PCounter syncCounter)
{
syncCounter->increment();
std::cout << "basicFiberSync1 start" << std::endl;
co_await AwaitCounter{syncCounter, 2};
std::cout << "basicFiberSync1 has resumed, counter is " << syncCounter << std::endl;
co_return;
}
FiberTask basicFiberSync2(PCounter syncCounter)
{
syncCounter->increment();
std::cout << "basicFiberSync2 start" << std::endl;
co_await AwaitCounter(syncCounter, 3);
std::cout << "basicFiberSync2 has resumed, counter is " << syncCounter << std::endl;
co_return;
}
BOOST_AUTO_TEST_CASE(basicFiberSync)
{
PCounter syncCounter = new Counter(1);
PCounter counter1 = new Counter();
FiberJob job1 = FiberJob(counter1, &basicFiberSync1, syncCounter);
JobQueue::runJobs(&job1, 1);
FiberJob job2 = FiberJob(counter1, &basicFiberSync2, syncCounter);
JobQueue::runJobs(&job2, 1);
while(counter1->lessThan(2))
std::this_thread::yield();
BOOST_CHECK_EQUAL(syncCounter->getValue(), 3);
}
FiberTask incrementJob(PCounter localCounter)
{
localCounter->increment();
co_return;
}
BOOST_AUTO_TEST_CASE(jobBatch)
{
PCounter localCounter = new Counter();
PCounter jobCounter = new Counter();
FiberJob jobs[256];
for(int i = 0; i < 256; ++i)
{
jobs[i] = FiberJob(jobCounter, JobPriority::HIGH, &incrementJob, localCounter);
}
JobQueue::runJobs(jobs, 256);
while(jobCounter->lessThan(256))
std::this_thread::yield();
BOOST_CHECK_EQUAL(localCounter->getValue(), 256);
}
BOOST_AUTO_TEST_SUITE_END()