feat(thread): add basic thread functions

This commit is contained in:
fallenoak 2023-03-04 10:50:12 -06:00 committed by GitHub
parent 0242759cbe
commit 39f4bd35a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 296 additions and 0 deletions

21
test/Thread.cpp Normal file
View file

@ -0,0 +1,21 @@
#include "bc/Thread.hpp"
#include "bc/Memory.hpp"
#include "test/Test.hpp"
void* ConstructInteger(void* value) {
auto ptr = reinterpret_cast<int32_t*>(Blizzard::Memory::Allocate(sizeof(int32_t)));
*ptr = *reinterpret_cast<int32_t*>(value);
return ptr;
}
TEST_CASE("Blizzard::Thread::RegisterLocalStorage", "[thread]") {
SECTION("constructs value and stores it in available TLS slot") {
Blizzard::Thread::TLSSlot slot {};
Blizzard::Thread::AllocateLocalStorage(&slot);
int32_t value = 12345;
auto ptr = Blizzard::Thread::RegisterLocalStorage(&slot, ConstructInteger, &value, nullptr);
REQUIRE(*reinterpret_cast<int32_t*>(ptr) == value);
}
}