mirror of
https://github.com/rock88/moonlight-nx
synced 2025-02-16 12:38:29 +00:00
Fix thread close on Switch
This commit is contained in:
parent
4aeabcf113
commit
2df5d3ec33
4 changed files with 41 additions and 37 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "Settings.hpp"
|
||||
#include "Limelight.h"
|
||||
#include "InputController.hpp"
|
||||
#include "GameStreamClient.hpp"
|
||||
#include <glad/glad.h>
|
||||
|
||||
#ifdef __SWITCH__
|
||||
|
@ -13,7 +14,7 @@
|
|||
#include <GLFW/glfw3.h>
|
||||
|
||||
GLFWgamepadstate glfw_gamepad_state;
|
||||
volatile int moonlight_exit = 0;
|
||||
int moonlight_exit = 0;
|
||||
|
||||
int width, height, fb_width, fb_height;
|
||||
|
||||
|
@ -98,8 +99,9 @@ int main(int argc, const char * argv[]) {
|
|||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
GameStreamClient::client()->stop();
|
||||
nanogui::leave();
|
||||
//nanogui::shutdown();
|
||||
nanogui::shutdown();
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
|
|
|
@ -13,28 +13,32 @@
|
|||
static std::mutex m_async_mutex;
|
||||
static std::vector<std::function<void()>> m_tasks;
|
||||
|
||||
#ifdef __SWITCH__
|
||||
#include <switch.h>
|
||||
extern int moonlight_exit;
|
||||
static volatile bool task_loop_active = true;
|
||||
|
||||
static void task_loop() {
|
||||
Thread thread;
|
||||
while (task_loop_active) {
|
||||
std::vector<std::function<void()>> m_tasks_copy; {
|
||||
std::lock_guard<std::mutex> guard(m_async_mutex);
|
||||
m_tasks_copy = m_tasks;
|
||||
m_tasks.clear();
|
||||
}
|
||||
|
||||
for (auto task: m_tasks_copy) {
|
||||
task();
|
||||
}
|
||||
|
||||
usleep(500'000);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __SWITCH__
|
||||
#include <switch.h>
|
||||
static Thread task_loop_thread;
|
||||
static void start_task_loop() {
|
||||
threadCreate(
|
||||
&thread,
|
||||
&task_loop_thread,
|
||||
[](void* a) {
|
||||
while (!moonlight_exit) {
|
||||
std::vector<std::function<void()>> m_tasks_copy; {
|
||||
std::lock_guard<std::mutex> guard(m_async_mutex);
|
||||
m_tasks_copy = m_tasks;
|
||||
m_tasks.clear();
|
||||
}
|
||||
|
||||
for (auto task: m_tasks_copy) {
|
||||
task();
|
||||
}
|
||||
|
||||
usleep(500'000);
|
||||
}
|
||||
task_loop();
|
||||
},
|
||||
NULL,
|
||||
NULL,
|
||||
|
@ -42,24 +46,12 @@ static void task_loop() {
|
|||
0x2C,
|
||||
-2
|
||||
);
|
||||
threadStart(&thread);
|
||||
threadStart(&task_loop_thread);
|
||||
}
|
||||
#else
|
||||
static void task_loop() {
|
||||
static void start_task_loop() {
|
||||
auto thread = std::thread([](){
|
||||
while (1) {
|
||||
std::vector<std::function<void()>> m_tasks_copy; {
|
||||
std::lock_guard<std::mutex> guard(m_async_mutex);
|
||||
m_tasks_copy = m_tasks;
|
||||
m_tasks.clear();
|
||||
}
|
||||
|
||||
for (auto task: m_tasks_copy) {
|
||||
task();
|
||||
}
|
||||
|
||||
usleep(500'000);
|
||||
}
|
||||
task_loop();
|
||||
});
|
||||
thread.detach();
|
||||
}
|
||||
|
@ -71,7 +63,16 @@ void perform_async(std::function<void()> task) {
|
|||
}
|
||||
|
||||
GameStreamClient::GameStreamClient() {
|
||||
task_loop();
|
||||
start_task_loop();
|
||||
}
|
||||
|
||||
void GameStreamClient::stop() {
|
||||
task_loop_active = false;
|
||||
|
||||
#ifdef __SWITCH__
|
||||
threadWaitForExit(&task_loop_thread);
|
||||
threadClose(&task_loop_thread);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GameStreamClient::connect(const std::string &address, ServerCallback<SERVER_DATA> callback) {
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
return m_server_data[address];
|
||||
}
|
||||
|
||||
void stop();
|
||||
void connect(const std::string &address, ServerCallback<SERVER_DATA> callback);
|
||||
void pair(const std::string &address, const std::string &pin, ServerCallback<bool> callback);
|
||||
void applist(const std::string &address, ServerCallback<PAPP_LIST> callback);
|
||||
|
|
2
third_party/nanogui
vendored
2
third_party/nanogui
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 45d1e7539dcade92040ec406f063c73b3cdfae13
|
||||
Subproject commit bd91d7f21e602ca96e3876adaa15a0a28e2a6c13
|
Loading…
Add table
Reference in a new issue