Emu: Implement BlockingCallFromMainThread

Reduces some copy-paste clutter throughout the project
This commit is contained in:
Megamouse 2022-06-24 19:58:26 +02:00 committed by Ivan
parent 7842812e24
commit 9cf7a63c77
13 changed files with 95 additions and 223 deletions

View file

@ -58,9 +58,9 @@ void headless_application::InitializeCallbacks()
return false;
};
callbacks.call_from_main_thread = [this](std::function<void()> func)
callbacks.call_from_main_thread = [this](std::function<void()> func, atomic_t<bool>* wake_up)
{
RequestCallFromMainThread(std::move(func));
RequestCallFromMainThread(std::move(func), wake_up);
};
callbacks.init_gs_render = []()
@ -156,7 +156,13 @@ void headless_application::InitializeCallbacks()
/**
* Using connects avoids timers being unable to be used in a non-qt thread. So, even if this looks stupid to just call func, it's succinct.
*/
void headless_application::CallFromMainThread(const std::function<void()>& func)
void headless_application::CallFromMainThread(const std::function<void()>& func, atomic_t<bool>* wake_up)
{
func();
if (wake_up)
{
*wake_up = true;
wake_up->notify_one();
}
}