#pragma once #include #include #include struct sthread; // A joinable thread on libretro-common's rthreads, in place of std::thread. // Like std::thread, a thread still joinable when destroyed or assigned over is a bug. class Thread { public: Thread() {} explicit Thread(std::function func); template Thread(F &&f, A &&a, Args &&...args) : Thread(std::function(std::bind(std::forward(f), std::forward(a), std::forward(args)...))) {} ~Thread(); Thread(const Thread &) = delete; Thread &operator=(const Thread &) = delete; Thread(Thread &&other) noexcept : thread_(other.thread_) { other.thread_ = nullptr; } Thread &operator=(Thread &&other) noexcept; bool joinable() const { return thread_ != nullptr; } void join(); void detach(); private: struct sthread *thread_ = nullptr; }; // An id for the calling thread, comparable with what another thread got from it. uintptr_t CurrentThreadId();