Files
ppsspp/Common/Thread/Thread.cpp
T
libretroadmin c60feaede6 Include the standard headers that newer code uses directly
These files use std::function, std::map, std::deque, std::unique_ptr or std::string_view and got
the header through others, which MSVC's standard library doesn't always do.
2026-10-09 09:46:15 +02:00

45 lines
1007 B
C++

#include <functional>
#include <rthreads/rthreads.h>
#include "Common/Log.h"
#include "Common/Thread/Thread.h"
static void ThreadEntry(void *arg) {
std::function<void()> *func = (std::function<void()> *)arg;
(*func)();
delete func;
}
Thread::Thread(std::function<void()> func) {
std::function<void()> *heapFunc = new std::function<void()>(std::move(func));
thread_ = sthread_create(&ThreadEntry, heapFunc);
_assert_msg_(thread_, "Failed to start a thread");
}
Thread::~Thread() {
_assert_msg_(!thread_, "Thread destroyed while still joinable");
}
Thread &Thread::operator=(Thread &&other) noexcept {
_assert_msg_(!thread_, "Thread assigned over while still joinable");
thread_ = other.thread_;
other.thread_ = nullptr;
return *this;
}
void Thread::join() {
_assert_(thread_);
sthread_join(thread_);
thread_ = nullptr;
}
void Thread::detach() {
_assert_(thread_);
sthread_detach(thread_);
thread_ = nullptr;
}
uintptr_t CurrentThreadId() {
return sthread_get_current_thread_id();
}