mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-06-29 06:22:39 +02:00
strat: statically allocate additional threads
This commit is contained in:
parent
e94abc4b5e
commit
a2b5865595
@ -20,13 +20,61 @@
|
|||||||
namespace sts::os {
|
namespace sts::os {
|
||||||
|
|
||||||
class Thread {
|
class Thread {
|
||||||
|
NON_COPYABLE(Thread);
|
||||||
|
NON_MOVEABLE(Thread);
|
||||||
private:
|
private:
|
||||||
::Thread thr = {};
|
::Thread thr;
|
||||||
public:
|
public:
|
||||||
Thread() {}
|
constexpr Thread() : thr{} { /* ... */ }
|
||||||
|
|
||||||
|
Result Initialize(ThreadFunc entry, void *arg, void *stack_mem, size_t stack_sz, int prio, int cpuid = -2) {
|
||||||
|
return threadCreate(&this->thr, entry, arg, stack_mem, stack_sz, prio, cpuid);
|
||||||
|
}
|
||||||
|
|
||||||
Result Initialize(ThreadFunc entry, void *arg, size_t stack_sz, int prio, int cpuid = -2) {
|
Result Initialize(ThreadFunc entry, void *arg, size_t stack_sz, int prio, int cpuid = -2) {
|
||||||
return threadCreate(&this->thr, entry, arg, stack_sz, prio, cpuid);
|
return threadCreate(&this->thr, entry, arg, nullptr, stack_sz, prio, cpuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
Handle GetHandle() const {
|
||||||
|
return this->thr.handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result Start() {
|
||||||
|
return threadStart(&this->thr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result Wait() {
|
||||||
|
return threadWaitForExit(&this->thr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result Join() {
|
||||||
|
R_TRY(threadWaitForExit(&this->thr));
|
||||||
|
R_TRY(threadClose(&this->thr));
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result CancelSynchronization() {
|
||||||
|
return svcCancelSynchronization(this->thr.handle);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<size_t StackSize>
|
||||||
|
class StaticThread {
|
||||||
|
NON_COPYABLE(StaticThread);
|
||||||
|
NON_MOVEABLE(StaticThread);
|
||||||
|
static_assert(util::IsAligned(StackSize, 0x1000), "StaticThread must have aligned resource size");
|
||||||
|
private:
|
||||||
|
alignas(0x1000) u8 stack_mem[StackSize];
|
||||||
|
::Thread thr;
|
||||||
|
public:
|
||||||
|
constexpr StaticThread() : stack_mem{}, thr{} { /* ... */ }
|
||||||
|
|
||||||
|
constexpr StaticThread(ThreadFunc entry, void *arg, int prio, int cpuid = -2) : StaticThread() {
|
||||||
|
R_ASSERT(this->Initialize(entry, arg, prio, cpuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
Result Initialize(ThreadFunc entry, void *arg, int prio, int cpuid = -2) {
|
||||||
|
return threadCreate(&this->thr, entry, arg, this->stack_mem, StackSize, prio, cpuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle GetHandle() const {
|
Handle GetHandle() const {
|
||||||
|
Loading…
Reference in New Issue
Block a user