mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-17 08:20:30 +02:00
Make threading lock-free
The core and the headless tools no longer use mutexes, condition variables, spinlocks, std::atomic, std::thread or volatile flags. Threads hand off through libretro-common's retro_atomic and rthreads plus a few small pieces on top of them in Common/Thread: Thread, MpscQueue, EventCounter, ParkingLot waits and ReaderGate. Every wait blocks until it's woken; nothing polls on a timer. State that only one thread touches just loses its lock. The PSP filesystem, sceIo and the savedata dialog now belong to the emulation thread: async reads and writes run when they're queued and complete later in emulated time, and the IO and savedata threads are gone. The friend finder only talks to the adhoc server and hands what it gets to the emulation thread. GPU init always runs on the thread that starts the game. The Vulkan render and compile queues, pipeline and render pass caches, delete list and SPIR-V cache, the GL render queue, the software renderer's jit caches, the file loader caches, the web debugger, UPnP, input, savestates, logging and the GE debugger all hand off through queues and atomics. The IR jit's spinning profiler thread goes. A CPU thread with nothing to run now sleeps until work is queued instead of spinning. Headless with --debugger waits for a client while stopped, and ends the run once every client that connected has left. Web server shutdown keeps servicing the CPU queue until the server has finished.
This commit is contained in:
1 parent
f0b97a2e90
commit
f1208a7a5a
211 files changed
+5465
-5625
No files matched your search
@@ -1,10 +1,11 @@
|
||||
#ifndef HTTPS_NOT_AVAILABLE
|
||||
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <retro_atomic.h>
|
||||
|
||||
#include "Common/Net/HTTPRequest.h"
|
||||
#include "Common/Net/HTTPNaettRequest.h"
|
||||
#include "Common/Thread/ThreadUtil.h"
|
||||
@@ -34,7 +35,7 @@ struct NaettBodySink {
|
||||
// naett reads the POST body in place while uploading, so it lives here too.
|
||||
std::string postData;
|
||||
// Written by us, read by the transfer thread.
|
||||
std::atomic<bool> cancelled{false};
|
||||
retro_atomic_int_t cancelled{ 0 };
|
||||
};
|
||||
|
||||
// Sinks belonging to requests that hadn't finished when they were torn down, which only happens
|
||||
@@ -54,7 +55,7 @@ void HTTPSShutdown() {
|
||||
|
||||
int HTTPSRequest::WriteBodyThunk(const void *source, int bytes, void *userData) {
|
||||
NaettBodySink *sink = (NaettBodySink *)userData;
|
||||
if (sink->cancelled) {
|
||||
if (retro_atomic_load_acquire_int(&sink->cancelled)) {
|
||||
// Taking less than we were given fails the request, which is how naett lets us stop a
|
||||
// transfer. Without this, cancelling only relabelled the result once it finished anyway.
|
||||
return 0;
|
||||
@@ -70,7 +71,7 @@ int HTTPSRequest::WriteBodyThunk(const void *source, int bytes, void *userData)
|
||||
void HTTPSRequest::Cancel() {
|
||||
Request::Cancel();
|
||||
if (sink_) {
|
||||
sink_->cancelled = true;
|
||||
retro_atomic_store_release_int(&sink_->cancelled, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +83,7 @@ void HTTPSRequest::Start() {
|
||||
// it once it finishes.
|
||||
sink_ = std::make_unique<NaettBodySink>();
|
||||
// In case someone managed to cancel us between construction and here.
|
||||
sink_->cancelled = IsCancelled();
|
||||
retro_atomic_store_release_int(&sink_->cancelled, IsCancelled() ? 1 : 0);
|
||||
sink_->postData = postData_;
|
||||
|
||||
std::vector<naettOption *> options;
|
||||
@@ -152,7 +153,7 @@ void HTTPSRequest::Join() {
|
||||
// that still exists. The process is on its way out; this is the last word on it.
|
||||
WARN_LOG(Log::HTTP, "Abandoning an unfinished request to '%s' - shutting down", url_.c_str());
|
||||
if (sink_) {
|
||||
sink_->cancelled = true;
|
||||
retro_atomic_store_release_int(&sink_->cancelled, 1);
|
||||
if (!g_abandonedSinks) {
|
||||
g_abandonedSinks = new std::vector<std::unique_ptr<NaettBodySink>>();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user