Music: fix concurrent access on destruction
This commit is contained in:
parent
916fecbf37
commit
a237102de9
|
|
@ -12,6 +12,7 @@
|
||||||
#include <Nazara/Utils/CallOnExit.hpp>
|
#include <Nazara/Utils/CallOnExit.hpp>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <optional>
|
||||||
#include <Nazara/Audio/Debug.hpp>
|
#include <Nazara/Audio/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
|
|
@ -397,6 +398,8 @@ namespace Nz
|
||||||
|
|
||||||
void Music::MusicThread(std::condition_variable& cv, std::mutex& m, std::exception_ptr& err, bool startPaused)
|
void Music::MusicThread(std::condition_variable& cv, std::mutex& m, std::exception_ptr& err, bool startPaused)
|
||||||
{
|
{
|
||||||
|
std::optional<std::lock_guard<std::recursive_mutex>> exitLock;
|
||||||
|
|
||||||
// Allocation of streaming buffers
|
// Allocation of streaming buffers
|
||||||
CallOnExit unqueueBuffers([&]
|
CallOnExit unqueueBuffers([&]
|
||||||
{
|
{
|
||||||
|
|
@ -442,6 +445,12 @@ namespace Nz
|
||||||
cv.notify_all();
|
cv.notify_all();
|
||||||
} // m & cv no longer exists from here
|
} // m & cv no longer exists from here
|
||||||
|
|
||||||
|
// From now, the source can be accessed from another thread, lock it before others destructors
|
||||||
|
CallOnExit lockSource([&]
|
||||||
|
{
|
||||||
|
exitLock.emplace(m_sourceLock);
|
||||||
|
});
|
||||||
|
|
||||||
// Reading loop (Filling new buffers as playing)
|
// Reading loop (Filling new buffers as playing)
|
||||||
while (m_streaming)
|
while (m_streaming)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue