[+] AuThreads::Spawn

This commit is contained in:
Reece Wilson 2023-09-20 05:33:37 +01:00
parent 7efde62c3c
commit d123850ac0
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,40 @@
/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Spawn.hpp
Date: 2023-09-20
Author: Reece
***/
#pragma once
namespace Aurora::Threading::Threads
{
static ThreadUnique_t Spawn(AuVoidFunc entrypoint,
bool bDetached = false,
AuUInt32 uStackSize = 0)
{
auto thread = ThreadUnique(ThreadInfo(
AuMakeShared<IThreadVectorsFunctional>(IThreadVectorsFunctional::OnEntry_t(std::bind(entrypoint)), IThreadVectorsFunctional::OnExit_t {}),
uStackSize
));
if (!thread)
{
SysPushErrorNested();
return ThreadUnique_t {};
}
if (!thread->Run())
{
SysPushErrorNested();
return ThreadUnique_t {};
}
if (bDetached)
{
thread->Detach();
}
return AuMove(thread);
}
}

View File

@ -14,6 +14,7 @@
#include "IAuroraThread.hpp"
#include "ThreadInfo.hpp"
#include "Thread.hpp"
#include "Spawn.hpp"
#include "TLSView.hpp"
#include "TLSVariable.hpp"
#include "TLSStaticVariable.hpp"