Android: Fix wait for emulation thread returning early
This commit is contained in:
parent
ac89379ca6
commit
f68ad7d0c3
|
@ -240,6 +240,7 @@ void AndroidHostInterface::RunOnEmulationThread(std::function<void()> function,
|
||||||
|
|
||||||
m_mutex.lock();
|
m_mutex.lock();
|
||||||
m_callback_queue.push_back(std::move(function));
|
m_callback_queue.push_back(std::move(function));
|
||||||
|
m_callbacks_outstanding.store(true);
|
||||||
m_sleep_cv.notify_one();
|
m_sleep_cv.notify_one();
|
||||||
|
|
||||||
if (blocking)
|
if (blocking)
|
||||||
|
@ -247,7 +248,7 @@ void AndroidHostInterface::RunOnEmulationThread(std::function<void()> function,
|
||||||
// TODO: Don't spin
|
// TODO: Don't spin
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (m_callback_queue.empty())
|
if (!m_callbacks_outstanding.load())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
m_mutex.unlock();
|
m_mutex.unlock();
|
||||||
|
@ -319,13 +320,18 @@ void AndroidHostInterface::EmulationThreadLoop()
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
while (!m_callback_queue.empty())
|
if (!m_callback_queue.empty())
|
||||||
{
|
{
|
||||||
auto callback = std::move(m_callback_queue.front());
|
do
|
||||||
m_callback_queue.pop_front();
|
{
|
||||||
lock.unlock();
|
auto callback = std::move(m_callback_queue.front());
|
||||||
callback();
|
m_callback_queue.pop_front();
|
||||||
lock.lock();
|
lock.unlock();
|
||||||
|
callback();
|
||||||
|
lock.lock();
|
||||||
|
}
|
||||||
|
while (!m_callback_queue.empty());
|
||||||
|
m_callbacks_outstanding.store(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_emulation_thread_stop_request.load())
|
if (m_emulation_thread_stop_request.load())
|
||||||
|
|
|
@ -86,6 +86,7 @@ private:
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
std::condition_variable m_sleep_cv;
|
std::condition_variable m_sleep_cv;
|
||||||
std::deque<std::function<void()>> m_callback_queue;
|
std::deque<std::function<void()>> m_callback_queue;
|
||||||
|
std::atomic_bool m_callbacks_outstanding{false};
|
||||||
|
|
||||||
std::thread m_emulation_thread;
|
std::thread m_emulation_thread;
|
||||||
std::atomic_bool m_emulation_thread_stop_request{false};
|
std::atomic_bool m_emulation_thread_stop_request{false};
|
||||||
|
|
Loading…
Reference in New Issue