mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-16 07:50:28 +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
@@ -226,7 +226,7 @@ void WebSocketServer::CloseAbnormally() {
|
||||
outBufOffset_ = 0;
|
||||
}
|
||||
|
||||
bool WebSocketServer::Process(float timeout) {
|
||||
bool WebSocketServer::Process(const intptr_t *wakeFds, int wakeCount) {
|
||||
if (!open_) {
|
||||
return false;
|
||||
}
|
||||
@@ -248,16 +248,22 @@ bool WebSocketServer::Process(float timeout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct timeval tv;
|
||||
tv.tv_sec = floor(timeout);
|
||||
tv.tv_usec = (timeout - floor(timeout)) * 1000000.0;
|
||||
|
||||
fd_set read;
|
||||
FD_ZERO(&read);
|
||||
// In case we closed due to protocol error, don't even try to read.
|
||||
if (!sentClose_) {
|
||||
FD_SET(fd_, &read);
|
||||
}
|
||||
intptr_t maxfd = (intptr_t)fd_;
|
||||
for (int i = 0; i < wakeCount; ++i) {
|
||||
if (wakeFds[i] == -1) {
|
||||
continue;
|
||||
}
|
||||
FD_SET((size_t)wakeFds[i], &read);
|
||||
if (wakeFds[i] > maxfd) {
|
||||
maxfd = wakeFds[i];
|
||||
}
|
||||
}
|
||||
|
||||
fd_set write;
|
||||
FD_ZERO(&write);
|
||||
@@ -266,7 +272,7 @@ bool WebSocketServer::Process(float timeout) {
|
||||
}
|
||||
|
||||
// First argument to select is the highest socket in the set + 1.
|
||||
int rval = select((int)fd_ + 1, &read, &write, nullptr, &tv);
|
||||
int rval = select((int)maxfd + 1, &read, &write, nullptr, nullptr);
|
||||
if (rval < 0) {
|
||||
const int err = socket_errno;
|
||||
#if !PPSSPP_PLATFORM(WINDOWS)
|
||||
@@ -276,17 +282,12 @@ bool WebSocketServer::Process(float timeout) {
|
||||
}
|
||||
#endif
|
||||
// Anything else isn't going to fix itself (a bad fd, say), and returning true on a call
|
||||
// that fails immediately means the caller busy-loops instead of being paced by the timeout.
|
||||
// that fails immediately would make the caller busy-loop.
|
||||
ERROR_LOG(Log::IO, "WebSocket select() failed: %d - closing connection", err);
|
||||
CloseAbnormally();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rval == 0) {
|
||||
// Timed out.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (FD_ISSET(fd_, &write)) {
|
||||
SendFlush();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user