Reece
e5e36bd887
[*] Fix deadlock in the async subsystem (NoLockShutdown vs Shutdown in exception handler) [+] Added ProccessMap NT variant [+] Added ToolHelp image profiling [*] Improved exception awareness [*] Delegated SpawnThread to isolated TU, ready for reuse for RunAs and XNU Open - now with horrible evil alloc that could fail [+] Added header for future api 'UtilRun' [*] Improve NT core detection [*] Changed small affinity bitmap to AuUInt64 instead of AuUInt32 [+] Added data structure to hold cpuids/affinity masks [+] Implemented logger sinks [+] Implemented logger glue logic [*] Began migrating older loggers to sink-based default devices [*] Minor refactors [*] Improved internal exception discarding, not yet nothrow capable [*] Minor create directory fix
76 lines
2.0 KiB
C++
76 lines
2.0 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: SpawnThread.Unix.cpp
|
|
Date:
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "Threads.hpp"
|
|
#include "SpawnThread.hpp"
|
|
|
|
#if defined(AURORA_HAS_PTHREADS)
|
|
#include <sched.h>
|
|
#endif
|
|
|
|
namespace Aurora::Threading::Threads
|
|
{
|
|
AuPair<bool, AuUInt> /*success, oshandle*/ SpawnThread(const AuFunction<void()> &entrypoint, const AuString &debugString, AuUInt32 staskSize)
|
|
{
|
|
pthread_attr_t tattr;
|
|
pthread_t handle;
|
|
|
|
if (!entrypoint)
|
|
{
|
|
return {false, 0};
|
|
}
|
|
|
|
// i dont like this allocate
|
|
auto callbackClone = _new AuFunction<void()>(entrypoint);
|
|
if (!callbackClone)
|
|
{
|
|
return {false, 0};
|
|
}
|
|
|
|
static auto callVoidPtr_f = [](void *that) -> void
|
|
{
|
|
auto handle = reinterpret_cast<AuFunction<void()> *>(that);
|
|
auto callMe = *handle;
|
|
delete handle;
|
|
callMe();
|
|
};
|
|
|
|
void *(*OSEP_f)(void *) = [](void *that) -> void *
|
|
{
|
|
auto thiz = reinterpret_cast<OSThread *>(that);
|
|
thiz->_ThreadEP();
|
|
return nullptr;
|
|
};
|
|
|
|
auto ret = pthread_attr_init(&tattr);
|
|
if (ret != 0)
|
|
{
|
|
SysPushErrorGen("Couldn't create thread: {}", debugString);
|
|
return {false, 0};
|
|
}
|
|
|
|
if (info_.stackSize)
|
|
{
|
|
ret = pthread_attr_setstacksize(&tattr, AuMin(AuUInt32(PTHREAD_STACK_MIN), info_.stackSize));
|
|
if (ret != 0)
|
|
{
|
|
SysPushErrorGen("Couldn't create thread: {}", debugString);
|
|
return {false, 0};
|
|
}
|
|
}
|
|
|
|
ret = pthread_create(&handle, &tattr, OSEP_f, callbackClone);
|
|
if (ret != 0)
|
|
{
|
|
SysPushErrorGen("Couldn't create thread: {}", debugString);
|
|
return {false, 0};
|
|
}
|
|
|
|
return {true, handle};
|
|
}
|
|
} |