Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "thread.hpp"
- extern "C" {
- #include <switch/kernel/svc.h>
- #include <switch/result.h>
- }
- static inline int getNextCpuId()
- {
- const auto currProcNum = svcGetCurrentProcessorNumber();
- const auto nextProcNum = (currProcNum + 1) % 4;
- if (nextProcNum == 3) //ew, kernel cpu
- return 0;
- else
- return (int)nextProcNum;
- }
- thread::thread(thread::FuncType&& func, size_t stackSize, int priority) : _func(std::move(func))
- {
- _status = threadCreate(&_thr, [](void* arg) { static_cast<thread*>(arg)->run(); }, this, stackSize, priority, getNextCpuId());
- if (R_FAILED(_status))
- return;
- _status = threadStart(&_thr);
- if (R_FAILED(_status))
- {
- threadClose(&_thr);
- return;
- }
- }
- Result thread::join()
- {
- if (R_FAILED(_status))
- return _status;
- return threadWaitForExit(&_thr);
- }
- thread::~thread()
- {
- if (R_SUCCEEDED(_status))
- {
- join();
- threadClose(&_thr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement