[*] Improved AuThreads::Spawn prototypes with new optional finalizer arg
This commit is contained in:
parent
58e8209cff
commit
41412876b6
@ -11,25 +11,49 @@ namespace Aurora::Threading::Threads
|
||||
{
|
||||
static ThreadUnique_t Spawn(AuVoidFunc entrypoint,
|
||||
bool bDetached = false,
|
||||
AuUInt32 uStackSize = 0)
|
||||
AuOptional<AuUInt32> optuStackSize = { 0 },
|
||||
AuOptional<AuString> optName = { })
|
||||
{
|
||||
auto thread = ThreadUnique(ThreadInfo(
|
||||
ThreadInfo threadInfo(
|
||||
AuMakeShared<IThreadVectorsFunctional>(IThreadVectorsFunctional::OnEntry_t(std::bind(entrypoint)), IThreadVectorsFunctional::OnExit_t {}),
|
||||
uStackSize
|
||||
));
|
||||
optuStackSize.ValueOr(0)
|
||||
);
|
||||
|
||||
if (!thread)
|
||||
SysCheckNotNullMemory(AuTryConstruct(threadInfo.name, optName.ValueOr(AuString {})), {});
|
||||
SysCheckNotNullMemory(threadInfo.callbacks, ThreadUnique_t {});
|
||||
|
||||
auto thread = ThreadUnique(threadInfo);
|
||||
SysCheckNotNullNested(thread, ThreadUnique_t {});
|
||||
|
||||
SysCheckNotNullNested(thread->Run(), ThreadUnique_t {});
|
||||
|
||||
if (bDetached)
|
||||
{
|
||||
SysPushErrorNested();
|
||||
return ThreadUnique_t {};
|
||||
thread->Detach();
|
||||
}
|
||||
|
||||
if (!thread->Run())
|
||||
{
|
||||
SysPushErrorNested();
|
||||
return ThreadUnique_t {};
|
||||
return AuMove(thread);
|
||||
}
|
||||
|
||||
static ThreadUnique_t Spawn(AuVoidFunc entrypoint,
|
||||
AuVoidFunc finalizer,
|
||||
bool bDetached = false,
|
||||
AuOptional<AuUInt32> optuStackSize = { 0 },
|
||||
AuOptional<AuString> optName = { })
|
||||
{
|
||||
ThreadInfo threadInfo(
|
||||
AuMakeShared<IThreadVectorsFunctional>(IThreadVectorsFunctional::OnEntry_t(std::bind(entrypoint)), IThreadVectorsFunctional::OnExit_t(std::bind(finalizer))),
|
||||
optuStackSize.ValueOr(0)
|
||||
);
|
||||
|
||||
SysCheckNotNullMemory(AuTryConstruct(threadInfo.name, optName.ValueOr(AuString {})), { });
|
||||
SysCheckNotNullMemory(threadInfo.callbacks, ThreadUnique_t {});
|
||||
|
||||
auto thread = ThreadUnique(threadInfo);
|
||||
SysCheckNotNullNested(thread, ThreadUnique_t {});
|
||||
|
||||
SysCheckNotNullNested(thread->Run(), ThreadUnique_t {});
|
||||
|
||||
if (bDetached)
|
||||
{
|
||||
thread->Detach();
|
||||
|
Loading…
Reference in New Issue
Block a user