From d0b82d3c3c3fef2edc5ac7a018f0c3a226fed7b7 Mon Sep 17 00:00:00 2001 From: David Reid Date: Thu, 30 Jan 2020 19:08:56 +1000 Subject: [PATCH] Try fixing a potential thread safety issue. --- miniaudio.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index e28f313a..ee5a6701 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -2431,7 +2431,7 @@ struct ma_device ma_context* pContext; ma_device_type type; ma_uint32 sampleRate; - ma_uint32 state; + volatile ma_uint32 state; /* The state of the device is variable and can change at any time on any thread, so tell the compiler as such with `volatile`. */ ma_device_callback_proc onData; ma_stop_proc onStop; void* pUserData; /* Application defined data. */ @@ -6167,10 +6167,7 @@ static MA_INLINE void ma_device__set_state(ma_device* pDevice, ma_uint32 newStat /* A helper for getting the state of the device. */ static MA_INLINE ma_uint32 ma_device__get_state(ma_device* pDevice) { - ma_uint32 state; - ma_atomic_exchange_32(&state, pDevice->state); - - return state; + return pDevice->state; }