Fix encoder thread destruction

This commit is contained in:
Patrick Nicolas
2024-07-25 11:56:45 +02:00
parent 142d453c98
commit af48d32c37
2 changed files with 26 additions and 37 deletions
+13 -12
View File
@@ -84,22 +84,23 @@ struct wivrn_comp_target : public comp_target
struct encoder_thread
{
int index;
os_thread_helper thread;
std::jthread thread;
pseudo_swapchain::status_type & gen;
std::jthread stopper;
encoder_thread(pseudo_swapchain::status_type & gen) :
gen(gen)
{
os_thread_helper_init(&thread);
}
encoder_thread(std::jthread && thread, pseudo_swapchain::status_type & gen) :
thread(std::move(thread)), gen(gen) {}
~encoder_thread()
{
os_thread_helper_signal_stop(&thread);
gen += 1;
gen.notify_all();
os_thread_helper_wait_locked(&thread);
os_thread_helper_destroy(&thread);
thread.request_stop();
// Encoder will be in a loop on the gen variable, wake them up
stopper = std::jthread([&]() {
while (not stopper.get_stop_token().stop_requested())
{
gen += 1;
gen.notify_all();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
} });
}
};
std::vector<encoder_settings> settings;