diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 2da136ede4..d7e30f9214 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -717,7 +717,7 @@ void waiter_map_t::notify(u64 signal_id) } } -bool squeue_test_exit(const volatile bool* do_exit) +bool squeue_test_exit() { - return Emu.IsStopped() || (do_exit && *do_exit); + return Emu.IsStopped(); } diff --git a/Utilities/Thread.h b/Utilities/Thread.h index 200b54b02d..a80097932b 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -162,7 +162,7 @@ public: void notify(u64 signal_id); }; -bool squeue_test_exit(const volatile bool* do_exit); +bool squeue_test_exit(); template class squeue_t @@ -213,7 +213,7 @@ public: return m_sync.read_relaxed().count == sq_size; } - bool push(const T& data, const volatile bool* do_exit = nullptr) + bool push(const T& data, const std::function& test_exit) { u32 pos = 0; @@ -236,7 +236,7 @@ public: return SQSVR_OK; })) { - if (res == SQSVR_FAILED && squeue_test_exit(do_exit)) + if (res == SQSVR_FAILED && (test_exit() || squeue_test_exit())) { return false; } @@ -261,14 +261,22 @@ public: return true; } - bool try_push(const T& data) + bool push(const T& data, const volatile bool* do_exit) { - static const volatile bool no_wait = true; - - return push(data, &no_wait); + return push(data, [do_exit](){ return do_exit && *do_exit; }); } - bool pop(T& data, const volatile bool* do_exit = nullptr) + bool push(const T& data) + { + return push(data, [](){ return false; }); + } + + bool try_push(const T& data) + { + return push(data, [](){ return true; }); + } + + bool pop(T& data, const std::function& test_exit) { u32 pos = 0; @@ -291,7 +299,7 @@ public: return SQSVR_OK; })) { - if (res == SQSVR_FAILED && squeue_test_exit(do_exit)) + if (res == SQSVR_FAILED && (test_exit() || squeue_test_exit())) { return false; } @@ -321,14 +329,22 @@ public: return true; } - bool try_pop(T& data) + bool pop(T& data, const volatile bool* do_exit) { - static const volatile bool no_wait = true; - - return pop(data, &no_wait); + return pop(data, [do_exit](){ return do_exit && *do_exit; }); } - bool peek(T& data, u32 start_pos = 0, const volatile bool* do_exit = nullptr) + bool pop(T& data) + { + return pop(data, [](){ return false; }); + } + + bool try_pop(T& data) + { + return pop(data, [](){ return true; }); + } + + bool peek(T& data, u32 start_pos, const std::function& test_exit) { assert(start_pos < sq_size); u32 pos = 0; @@ -352,7 +368,7 @@ public: return SQSVR_OK; })) { - if (res == SQSVR_FAILED && squeue_test_exit(do_exit)) + if (res == SQSVR_FAILED && (test_exit() || squeue_test_exit())) { return false; } @@ -375,11 +391,19 @@ public: return true; } + bool peek(T& data, u32 start_pos, const volatile bool* do_exit) + { + return peek(data, start_pos, [do_exit](){ return do_exit && *do_exit; }); + } + + bool peek(T& data, u32 start_pos = 0) + { + return peek(data, start_pos, [](){ return false; }); + } + bool try_peek(T& data, u32 start_pos = 0) { - static const volatile bool no_wait = true; - - return peek(data, start_pos, &no_wait); + return peek(data, start_pos, [](){ return true; }); } class squeue_data_t diff --git a/rpcs3/Emu/Audio/AL/OpenALThread.h b/rpcs3/Emu/Audio/AL/OpenALThread.h index 4d8f72a821..a02a100435 100644 --- a/rpcs3/Emu/Audio/AL/OpenALThread.h +++ b/rpcs3/Emu/Audio/AL/OpenALThread.h @@ -24,4 +24,4 @@ public: virtual void Close(); virtual void Stop(); virtual void AddData(const void* src, int size); -}; \ No newline at end of file +}; diff --git a/rpcs3/Emu/Audio/Null/NullAudioThread.h b/rpcs3/Emu/Audio/Null/NullAudioThread.h index 15dd40e12c..46de961af2 100644 --- a/rpcs3/Emu/Audio/Null/NullAudioThread.h +++ b/rpcs3/Emu/Audio/Null/NullAudioThread.h @@ -15,4 +15,4 @@ public: virtual void Close() {} virtual void Stop() {} virtual void AddData(const void* src, int size) {} -}; \ No newline at end of file +}; diff --git a/rpcs3/Emu/Audio/XAudio2/XAudio2Thread.cpp b/rpcs3/Emu/Audio/XAudio2/XAudio2Thread.cpp index ba414bcddd..d5b5e2b5e9 100644 --- a/rpcs3/Emu/Audio/XAudio2/XAudio2Thread.cpp +++ b/rpcs3/Emu/Audio/XAudio2/XAudio2Thread.cpp @@ -15,6 +15,7 @@ void XAudio2Thread::Init() { HRESULT hr = S_OK; +#if (_WIN32_WINNT < 0x0602) hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); if (FAILED(hr)) { @@ -22,6 +23,7 @@ void XAudio2Thread::Init() Emu.Pause(); return; } +#endif hr = XAudio2Create(&m_xaudio2_instance, 0, XAUDIO2_DEFAULT_PROCESSOR); if (FAILED(hr)) @@ -50,6 +52,10 @@ void XAudio2Thread::Quit() m_xaudio2_instance->StopEngine(); m_xaudio2_instance->Release(); m_xaudio2_instance = nullptr; + +#if (_WIN32_WINNT < 0x0602) + CoUninitialize(); +#endif } void XAudio2Thread::Play() @@ -131,4 +137,4 @@ void XAudio2Thread::AddData(const void* src, int size) Emu.Pause(); } } -#endif \ No newline at end of file +#endif diff --git a/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp b/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp index db77b18b28..815668386d 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp @@ -84,7 +84,7 @@ int cellAudioInit() while (g_audio.state.read_relaxed() == AUDIO_STATE_INITIALIZED && !Emu.IsStopped()) { float* buffer; - if (out_queue.pop(buffer)) + if (out_queue.pop(buffer, [](){ return g_audio.state.read_relaxed() != AUDIO_STATE_INITIALIZED; })) { if (use_u16) { @@ -343,7 +343,10 @@ int cellAudioInit() memset(out_buffer[out_pos].get(), 0, out_buffer_size * sizeof(float)); } - out_queue.push(out_buffer[out_pos].get()); + if (!out_queue.push(out_buffer[out_pos].get(), [](){ return g_audio.state.read_relaxed() != AUDIO_STATE_INITIALIZED; })) + { + break; + } //const u64 stamp2 = get_system_time();