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

@ -1627,19 +1627,11 @@ void camera_context::operator()()
else
{
std::lock_guard lock(mutex);
atomic_t<bool> wake_up = false;
Emu.CallFromMainThread([&]()
Emu.BlockingCallFromMainThread([&]()
{
send_frame_update_event = handler ? on_handler_state(handler->get_state()) : true;
wake_up = true;
wake_up.notify_one();
});
while (!wake_up && !Emu.IsStopped())
{
thread_ctrl::wait_on(wake_up, false);
}
}
}
@ -1704,9 +1696,8 @@ void camera_context::operator()()
bool camera_context::open_camera()
{
bool result = true;
atomic_t<bool> wake_up = false;
Emu.CallFromMainThread([&wake_up, &result, this]()
Emu.BlockingCallFromMainThread([&result, this]()
{
handler.reset();
handler = Emu.GetCallbacks().get_camera_handler();
@ -1715,15 +1706,8 @@ bool camera_context::open_camera()
handler->open_camera();
result = on_handler_state(handler->get_state());
}
wake_up = true;
wake_up.notify_one();
});
while (!wake_up && !Emu.IsStopped())
{
thread_ctrl::wait_on(wake_up, false);
}
return result;
}
@ -1738,20 +1722,11 @@ bool camera_context::start_camera()
handler->set_resolution(info.width, info.height);
handler->set_format(info.format, info.bytesize);
atomic_t<bool> wake_up = false;
Emu.CallFromMainThread([&wake_up, &result, this]()
Emu.BlockingCallFromMainThread([&result, this]()
{
handler->start_camera();
result = on_handler_state(handler->get_state());
wake_up = true;
wake_up.notify_one();
});
while (!wake_up && !Emu.IsStopped())
{
thread_ctrl::wait_on(wake_up, false);
}
}
return result;
@ -1763,19 +1738,10 @@ bool camera_context::get_camera_frame(u8* dst, u32& width, u32& height, u64& fra
if (handler)
{
atomic_t<bool> wake_up = false;
Emu.CallFromMainThread([&]()
Emu.BlockingCallFromMainThread([&]()
{
result = on_handler_state(handler->get_image(dst, info.bytesize, width, height, frame_number, bytes_read));
wake_up = true;
wake_up.notify_one();
});
while (!wake_up && !Emu.IsStopped())
{
thread_ctrl::wait_on(wake_up, false);
}
}
return result;
@ -1785,19 +1751,10 @@ void camera_context::stop_camera()
{
if (handler)
{
atomic_t<bool> wake_up = false;
Emu.CallFromMainThread([&wake_up, this]()
Emu.BlockingCallFromMainThread([this]()
{
handler->stop_camera();
wake_up = true;
wake_up.notify_one();
});
while (!wake_up && !Emu.IsStopped())
{
thread_ctrl::wait_on(wake_up, false);
}
}
}
@ -1805,19 +1762,10 @@ void camera_context::close_camera()
{
if (handler)
{
atomic_t<bool> wake_up = false;
Emu.CallFromMainThread([&wake_up, this]()
Emu.BlockingCallFromMainThread([this]()
{
handler->close_camera();
wake_up = true;
wake_up.notify_one();
});
while (!wake_up && !Emu.IsStopped())
{
thread_ctrl::wait_on(wake_up, false);
}
}
}