mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-25 19:44:57 +00:00
* libkernel: Cleanup some function places * kernel: Refactor thread functions * kernel: It builds * kernel: Fix a bunch of bugs, kernel thread heap * kernel: File cleanup pt1 * File cleanup pt2 * File cleanup pt3 * File cleanup pt4 * kernel: Add missing funcs * kernel: Add basic exceptions for linux * gnmdriver: Add workload functions * kernel: Fix new pthreads code on macOS. (#1441) * kernel: Downgrade edeadlk to log * gnmdriver: Add sceGnmSubmitCommandBuffersForWorkload * exception: Add context register population for macOS. (#1444) * kernel: Pthread rewrite touchups for Windows * kernel: Multiplatform thread implementation * mutex: Remove spamming log * pthread_spec: Make assert into a log * pthread_spec: Zero initialize array * Attempt to fix non-Windows builds * hotfix: change incorrect NID for scePthreadAttrSetaffinity * scePthreadAttrSetaffinity implementation * Attempt to fix Linux * windows: Address a bunch of address space problems * address_space: Fix unmap of region surrounded by placeholders * libs: Reduce logging * pthread: Implement condvar with waitable atomics and sleepqueue * sleepq: Separate and make faster * time: Remove delay execution * Causes high cpu usage in Tohou Luna Nights * kernel: Cleanup files again * pthread: Add missing include * semaphore: Use binary_semaphore instead of condvar * Seems more reliable * libraries/sysmodule: log module on `sceSysmoduleIsLoaded` * libraries/kernel: implement `scePthreadSetPrio` --------- Co-authored-by: squidbus <175574877+squidbus@users.noreply.github.com> Co-authored-by: Daniel R. <47796739+polybiusproxy@users.noreply.github.com>
73 lines
1.7 KiB
C++
73 lines
1.7 KiB
C++
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
#include "common/polyfill_thread.h"
|
|
#include "core/libraries/kernel/threads/pthread.h"
|
|
|
|
namespace Core::Loader {
|
|
class SymbolsResolver;
|
|
}
|
|
|
|
namespace Libraries::Kernel {
|
|
|
|
int PS4_SYSV_ABI posix_pthread_attr_init(PthreadAttrT* attr);
|
|
|
|
int PS4_SYSV_ABI posix_pthread_attr_destroy(PthreadAttrT* attr);
|
|
|
|
int PS4_SYSV_ABI posix_pthread_create(PthreadT* thread, const PthreadAttrT* attr,
|
|
PthreadEntryFunc start_routine, void* arg);
|
|
|
|
int PS4_SYSV_ABI posix_pthread_join(PthreadT pthread, void** thread_return);
|
|
|
|
void RegisterThreads(Core::Loader::SymbolsResolver* sym);
|
|
|
|
class Thread {
|
|
public:
|
|
explicit Thread() = default;
|
|
~Thread() {
|
|
Stop();
|
|
}
|
|
|
|
void Run(std::function<void(std::stop_token)>&& func) {
|
|
this->func = std::move(func);
|
|
PthreadAttrT attr{};
|
|
posix_pthread_attr_init(&attr);
|
|
posix_pthread_create(&thread, &attr, RunWrapper, this);
|
|
posix_pthread_attr_destroy(&attr);
|
|
}
|
|
|
|
void Join() {
|
|
if (thread) {
|
|
posix_pthread_join(thread, nullptr);
|
|
thread = nullptr;
|
|
}
|
|
}
|
|
|
|
bool Joinable() const {
|
|
return thread != nullptr;
|
|
}
|
|
|
|
void Stop() {
|
|
if (Joinable()) {
|
|
stop.request_stop();
|
|
Join();
|
|
}
|
|
}
|
|
|
|
static void* PS4_SYSV_ABI RunWrapper(void* arg) {
|
|
Thread* thr = (Thread*)arg;
|
|
thr->func(thr->stop.get_token());
|
|
return nullptr;
|
|
}
|
|
|
|
private:
|
|
PthreadT thread{};
|
|
std::function<void(std::stop_token)> func;
|
|
std::stop_source stop;
|
|
};
|
|
|
|
} // namespace Libraries::Kernel
|