mirror of
https://github.com/citra-emu/citra.git
synced 2024-12-18 23:00:04 +00:00
Use SPSCQueue::PopWait in Scripting
This commit is contained in:
parent
9b49a79a72
commit
7efe60ed23
@ -106,10 +106,8 @@ void RPCServer::HandleRequestsLoop() {
|
||||
|
||||
LOG_INFO(RPC_Server, "Request handler started.");
|
||||
|
||||
while (true) {
|
||||
std::unique_lock<std::mutex> lock(request_queue_mutex);
|
||||
request_queue_cv.wait(lock, [&] { return !running || request_queue.Pop(request_packet); });
|
||||
if (!running) {
|
||||
while (request_queue.PopWait(request_packet)) {
|
||||
if (!request_packet) {
|
||||
break;
|
||||
}
|
||||
HandleSingleRequest(std::move(request_packet));
|
||||
@ -117,23 +115,18 @@ void RPCServer::HandleRequestsLoop() {
|
||||
}
|
||||
|
||||
void RPCServer::QueueRequest(std::unique_ptr<RPC::Packet> request) {
|
||||
std::unique_lock<std::mutex> lock(request_queue_mutex);
|
||||
request_queue.Push(std::move(request));
|
||||
request_queue_cv.notify_one();
|
||||
}
|
||||
|
||||
void RPCServer::Start() {
|
||||
running = true;
|
||||
const auto threadFunction = [this]() { HandleRequestsLoop(); };
|
||||
request_handler_thread = std::thread(threadFunction);
|
||||
server.Start();
|
||||
}
|
||||
|
||||
void RPCServer::Stop() {
|
||||
running = false;
|
||||
request_queue_cv.notify_one();
|
||||
request_handler_thread.join();
|
||||
server.Stop();
|
||||
request_handler_thread.join();
|
||||
}
|
||||
|
||||
}; // namespace RPC
|
||||
|
@ -31,10 +31,7 @@ private:
|
||||
|
||||
Server server;
|
||||
Common::SPSCQueue<std::unique_ptr<Packet>> request_queue;
|
||||
bool running = false;
|
||||
std::thread request_handler_thread;
|
||||
std::mutex request_queue_mutex;
|
||||
std::condition_variable request_queue_cv;
|
||||
};
|
||||
|
||||
} // namespace RPC
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <functional>
|
||||
|
||||
#include "common/threadsafe_queue.h"
|
||||
#include "core/core.h"
|
||||
#include "core/rpc/rpc_server.h"
|
||||
#include "core/rpc/server.h"
|
||||
|
@ -52,7 +52,8 @@ void ZMQServer::WorkerLoop() {
|
||||
LOG_WARNING(RPC_Server, "Failed to receive data on ZeroMQ socket");
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Packet> end_packet = nullptr;
|
||||
new_request_callback(std::move(end_packet));
|
||||
// Destroying the socket must be done by this thread.
|
||||
zmq_socket.reset();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user