Own runtime threads and thin platform/canvas seams
This commit is contained in:
@@ -52,20 +52,23 @@ void AppRuntime::render_thread_tick(App& app)
|
||||
}
|
||||
}
|
||||
|
||||
void AppRuntime::render_thread_main(App& app)
|
||||
void AppRuntime::render_thread_main(App& app, std::stop_token stop_token)
|
||||
{
|
||||
BT_SetTerminate();
|
||||
|
||||
render_thread_id_ = std::this_thread::get_id();
|
||||
render_running_ = pp::app::plan_app_thread_start().mark_running;
|
||||
while (render_running_)
|
||||
while (render_running_ && !stop_token.stop_requested())
|
||||
{
|
||||
std::deque<AppTask> working_list;
|
||||
pp::app::AppQueueDrainPlan drain_plan;
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(render_task_mutex_);
|
||||
render_cv_.wait(lock, [this] { return render_tasklist_.empty() && render_running_ ? false : true; });
|
||||
render_cv_.wait(lock, [this, &stop_token]
|
||||
{
|
||||
return stop_token.stop_requested() || !render_running_ || !render_tasklist_.empty();
|
||||
});
|
||||
drain_plan = pp::app::plan_app_render_queue_drain(render_tasklist_.size());
|
||||
working_list = std::move(render_tasklist_);
|
||||
}
|
||||
@@ -124,7 +127,7 @@ void AppRuntime::ui_thread_tick(App& app)
|
||||
}
|
||||
}
|
||||
|
||||
void AppRuntime::ui_thread_main(App& app)
|
||||
void AppRuntime::ui_thread_main(App& app, std::stop_token stop_token)
|
||||
{
|
||||
BT_SetTerminate();
|
||||
|
||||
@@ -141,14 +144,16 @@ void AppRuntime::ui_thread_main(App& app)
|
||||
float t_fps_counter = 0;
|
||||
float t_reloader = 0;
|
||||
int rendered_frames = 0;
|
||||
while (ui_running_)
|
||||
while (ui_running_ && !stop_token.stop_requested())
|
||||
{
|
||||
std::deque<AppTask> working_list;
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(ui_task_mutex_);
|
||||
ui_cv_.wait_for(lock, std::chrono::milliseconds(app.idle_ms),
|
||||
[this] { return ui_tasklist_.empty() && ui_running_ ? false : true; });
|
||||
ui_cv_.wait_for(lock, std::chrono::milliseconds(app.idle_ms), [this, &stop_token]
|
||||
{
|
||||
return stop_token.stop_requested() || !ui_running_ || !ui_tasklist_.empty();
|
||||
});
|
||||
working_list = std::move(ui_tasklist_);
|
||||
}
|
||||
|
||||
@@ -223,7 +228,10 @@ void AppRuntime::render_thread_start(App& app)
|
||||
{
|
||||
const auto plan = pp::app::plan_app_thread_start();
|
||||
if (plan.start_thread)
|
||||
render_thread_ = std::thread(&AppRuntime::render_thread_main, this, std::ref(app));
|
||||
render_thread_ = std::jthread([this, &app](std::stop_token stop_token)
|
||||
{
|
||||
render_thread_main(app, stop_token);
|
||||
});
|
||||
render_running_ = plan.mark_running;
|
||||
}
|
||||
|
||||
@@ -232,6 +240,8 @@ void AppRuntime::render_thread_stop()
|
||||
const auto plan = pp::app::plan_app_thread_stop(render_thread_.joinable());
|
||||
if (plan.mark_not_running)
|
||||
render_running_ = false;
|
||||
if (plan.join_thread)
|
||||
render_thread_.request_stop();
|
||||
if (plan.notify_worker)
|
||||
render_cv_.notify_all();
|
||||
if (plan.join_thread)
|
||||
@@ -242,7 +252,10 @@ void AppRuntime::ui_thread_start(App& app)
|
||||
{
|
||||
const auto plan = pp::app::plan_app_thread_start();
|
||||
if (plan.start_thread)
|
||||
ui_thread_ = std::thread(&AppRuntime::ui_thread_main, this, std::ref(app));
|
||||
ui_thread_ = std::jthread([this, &app](std::stop_token stop_token)
|
||||
{
|
||||
ui_thread_main(app, stop_token);
|
||||
});
|
||||
ui_running_ = plan.mark_running;
|
||||
}
|
||||
|
||||
@@ -251,6 +264,8 @@ void AppRuntime::ui_thread_stop()
|
||||
const auto plan = pp::app::plan_app_thread_stop(ui_thread_.joinable());
|
||||
if (plan.mark_not_running)
|
||||
ui_running_ = false;
|
||||
if (plan.join_thread)
|
||||
ui_thread_.request_stop();
|
||||
if (plan.notify_worker)
|
||||
ui_cv_.notify_all();
|
||||
if (plan.join_thread)
|
||||
|
||||
Reference in New Issue
Block a user