mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-06-03 21:24:59 -06:00
Reimplement mutex
This commit is contained in:
parent
c9109c59c5
commit
f80454e17c
@ -133,15 +133,11 @@ int SDLControllerProvider::get_index(size_t guid_index, const SDL_GUID& guid) co
|
|||||||
|
|
||||||
MotionSample SDLControllerProvider::motion_sample(SDL_JoystickID diid)
|
MotionSample SDLControllerProvider::motion_sample(SDL_JoystickID diid)
|
||||||
{
|
{
|
||||||
|
std::shared_lock lock(m_mutex);
|
||||||
|
|
||||||
auto it = m_motion_states.find(diid);
|
auto it = m_motion_states.find(diid);
|
||||||
|
|
||||||
if (it == m_motion_states.end())
|
return (it != m_motion_states.end()) ? it->second.data : MotionSample{};
|
||||||
{
|
|
||||||
return MotionSample{};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::scoped_lock lock(it->second.mtx);
|
|
||||||
return it->second.data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLControllerProvider::event_thread()
|
void SDLControllerProvider::event_thread()
|
||||||
@ -203,9 +199,12 @@ void SDLControllerProvider::event_thread()
|
|||||||
{
|
{
|
||||||
SDL_JoystickID id = event.gsensor.which;
|
SDL_JoystickID id = event.gsensor.which;
|
||||||
uint64_t ts = event.gsensor.timestamp;
|
uint64_t ts = event.gsensor.timestamp;
|
||||||
auto& state = m_motion_states[id];
|
|
||||||
|
|
||||||
|
std::scoped_lock lock(m_mutex);
|
||||||
|
|
||||||
|
auto& state = m_motion_states[id];
|
||||||
auto& tracking = state.tracking;
|
auto& tracking = state.tracking;
|
||||||
|
|
||||||
if (event.gsensor.sensor == SDL_SENSOR_ACCEL)
|
if (event.gsensor.sensor == SDL_SENSOR_ACCEL)
|
||||||
{
|
{
|
||||||
const auto dif = ts - tracking.lastTimestampAccel;
|
const auto dif = ts - tracking.lastTimestampAccel;
|
||||||
@ -266,7 +265,6 @@ void SDLControllerProvider::event_thread()
|
|||||||
}
|
}
|
||||||
|
|
||||||
state.handler.processMotionSample(tsDifD, tracking.gyro.x, tracking.gyro.y, tracking.gyro.z, tracking.acc.x, -tracking.acc.y, -tracking.acc.z);
|
state.handler.processMotionSample(tsDifD, tracking.gyro.x, tracking.gyro.y, tracking.gyro.z, tracking.acc.x, -tracking.acc.y, -tracking.acc.z);
|
||||||
std::scoped_lock lock(state.mtx);
|
|
||||||
state.data = state.handler.getMotionSample();
|
state.data = state.handler.getMotionSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,8 @@ private:
|
|||||||
|
|
||||||
std::atomic_bool m_running = false;
|
std::atomic_bool m_running = false;
|
||||||
std::thread m_thread;
|
std::thread m_thread;
|
||||||
|
mutable std::shared_mutex m_mutex;
|
||||||
|
|
||||||
struct MotionInfoTracking
|
struct MotionInfoTracking
|
||||||
{
|
{
|
||||||
uint64 lastTimestampGyro{};
|
uint64 lastTimestampGyro{};
|
||||||
@ -49,7 +50,6 @@ private:
|
|||||||
{
|
{
|
||||||
WiiUMotionHandler handler;
|
WiiUMotionHandler handler;
|
||||||
MotionSample data;
|
MotionSample data;
|
||||||
mutable std::mutex mtx;
|
|
||||||
MotionInfoTracking tracking;
|
MotionInfoTracking tracking;
|
||||||
|
|
||||||
MotionState() = default;
|
MotionState() = default;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user