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
-1
View File
@@ -5,6 +5,5 @@ 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 -50
View File
@@ -1,6 +1,7 @@
#include "EngineTest.h"
#include "Containers/Array.h"
#include "MinimalEngine.h"
#include <algorithm>
#include <time.h>
#include <chrono>
#include <boost/test/unit_test.hpp>
@@ -138,56 +139,6 @@ BOOST_AUTO_TEST_CASE(refptr_interaction)
}
}
/*BOOST_AUTO_TEST_CASE(benchmark)
{
using namespace std::chrono;
srand(time(NULL));
const uint32 TEST_SIZE = 1024 * 256;
uint32* testSet = new uint32[TEST_SIZE];
#pragma loop( hint_parallel( 0 ) )
for (int i = 0; i < TEST_SIZE; ++i)
{
testSet[i] = rand();
}
high_resolution_clock::time_point start_vector = high_resolution_clock::now();
std::vector<uint32> vec;
for (int i = 0; i < TEST_SIZE; ++i)
{
vec.push_back(testSet[i]);
}
high_resolution_clock::time_point end_vector = high_resolution_clock::now();
float time_vector = duration_cast<milliseconds>(end_vector - start_vector).count();
std::random_shuffle(testSet, testSet + TEST_SIZE);
high_resolution_clock::time_point start_remove_vector = high_resolution_clock::now();
for (int i = 0; i < TEST_SIZE; ++i)
{
vec.erase(std::find(vec.begin(), vec.end(), testSet[i]));
}
high_resolution_clock::time_point end_remove_vector = high_resolution_clock::now();
float remove_vector = duration_cast<milliseconds>(end_remove_vector - start_remove_vector).count();
high_resolution_clock::time_point start_array = high_resolution_clock::now();
Array<uint32> arr;
for (int i = 0; i < TEST_SIZE; ++i)
{
arr.add(testSet[i]);
}
high_resolution_clock::time_point end_array = high_resolution_clock::now();
float time_array = duration_cast<milliseconds>(end_array - start_array).count();
high_resolution_clock::time_point start_remove_array = high_resolution_clock::now();
for (int i = 0; i < TEST_SIZE; ++i)
{
arr.remove(arr.find(testSet[i]), false);
}
high_resolution_clock::time_point end_remove_array = high_resolution_clock::now();
float remove_array = duration_cast<milliseconds>(end_remove_array - start_remove_array).count();
std::cout << "Vector: " << time_vector << "ms Array: " << time_array << "ms" << std::endl;
std::cout << "Vector remove: " << remove_vector << "ms Array remove: " << remove_array << "ms" << std::endl;
delete[] testSet;
}*/
BOOST_AUTO_TEST_SUITE_END()
+3
View File
@@ -21,6 +21,9 @@ BOOST_AUTO_TEST_CASE(insert_find_basic)
map[4] = 4;
BOOST_REQUIRE_EQUAL(map[2], 5);
BOOST_REQUIRE_EQUAL(map[4], 4);
BOOST_REQUIRE_EQUAL(map.find(2)->value, 5);
BOOST_REQUIRE_EQUAL(map.find(4)->value, 4);
//BOOST_REQUIRE_EQUAL(map.find(5), map.end());
}
BOOST_AUTO_TEST_CASE(for_each)
+31 -4
View File
@@ -1,7 +1,6 @@
#include "EngineTest.h"
#include "MinimalEngine.h"
#define BOOST_TEST_MODULE SeeleEngine
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
using namespace Seele;
@@ -34,7 +33,6 @@ BOOST_AUTO_TEST_CASE(basic_refcount)
}
BOOST_REQUIRE_EQUAL(ptr->data, 10);
}
std::shared_ptr<DeclStruct> test;
}
struct DeclStruct
{
@@ -76,10 +74,39 @@ BOOST_AUTO_TEST_CASE(inheritance_cast)
BOOST_AUTO_TEST_CASE(unique_ptr)
{
UniquePtr<TestStruct> uptr = new TestStruct();
UniquePtr<TestStruct> uptr2 = std::move(uptr);
Seele::UniquePtr<TestStruct> uptr = new TestStruct();
Seele::UniquePtr<TestStruct> uptr2 = std::move(uptr);
BOOST_REQUIRE_EQUAL(uptr2->data, 10);
BOOST_REQUIRE_EQUAL(uptr.isValid(), false);
}
struct ThisReference
{
ThisReference()
{
}
~ThisReference()
{
data = 12;
}
Seele::RefPtr<ThisReference> getRef()
{
return this;
}
uint32 data = 1;
};
BOOST_AUTO_TEST_CASE(this_reference)
{
Seele::RefPtr<ThisReference> ptr2;
{
Seele::RefPtr<ThisReference> ptr = new ThisReference();
BOOST_REQUIRE_EQUAL(ptr->data, 1);
ptr2 = ptr->getRef();
BOOST_REQUIRE_EQUAL(ptr2->data, 1);
ptr2->data = 5;
BOOST_REQUIRE_EQUAL(ptr->data, 5);
}
BOOST_REQUIRE_EQUAL(ptr2->data, 5);
}
BOOST_AUTO_TEST_SUITE_END()
-5
View File
@@ -1,5 +0,0 @@
target_sources(Seele_unit_tests
PRIVATE
../../../src/Engine/Fibers/JobQueue.cpp
../../../src/Engine/Fibers/Fibers.cpp
Fibers.cpp)
-61
View File
@@ -1,61 +0,0 @@
#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()