From d7d40b3c56df8e31d018477a5bd2abe3a6e4e550 Mon Sep 17 00:00:00 2001 From: wwylele Date: Thu, 29 Dec 2016 21:18:36 +0200 Subject: Frontend: make motion sensor interfaced thread-safe --- src/core/frontend/emu_window.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/core/frontend/emu_window.cpp') diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index 13c7f3de2..1541cc39d 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp @@ -93,6 +93,8 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { void EmuWindow::AccelerometerChanged(float x, float y, float z) { constexpr float coef = 512; + std::lock_guard lock(accel_mutex); + // TODO(wwylele): do a time stretch as it in GyroscopeChanged // The time stretch formula should be like // stretched_vector = (raw_vector - gravity) * stretch_ratio + gravity @@ -106,6 +108,7 @@ void EmuWindow::GyroscopeChanged(float x, float y, float z) { float coef = GetGyroscopeRawToDpsCoefficient(); float stretch = FULL_FPS / Common::Profiling::GetTimingResultsAggregator()->GetAggregatedResults().fps; + std::lock_guard lock(gyro_mutex); gyro_x = x * coef * stretch; gyro_y = y * coef * stretch; gyro_z = z * coef * stretch; -- cgit v1.2.3