mirror of
https://github.com/rwengine/openrw.git
synced 2024-10-06 09:07:19 +02:00
Fixes for thread sanitizer
This commit is contained in:
parent
1b588da1d1
commit
c234eb00f6
@ -20,8 +20,8 @@ struct SoundBuffer {
|
|||||||
bool isStopped() const;
|
bool isStopped() const;
|
||||||
|
|
||||||
virtual void play();
|
virtual void play();
|
||||||
void pause();
|
virtual void pause();
|
||||||
void stop();
|
virtual void stop();
|
||||||
|
|
||||||
void setPosition(const glm::vec3& position);
|
void setPosition(const glm::vec3& position);
|
||||||
void setLooping(bool looping);
|
void setLooping(bool looping);
|
||||||
|
@ -18,16 +18,18 @@ SoundBufferStreamed::SoundBufferStreamed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SoundBufferStreamed::~SoundBufferStreamed() {
|
SoundBufferStreamed::~SoundBufferStreamed() {
|
||||||
alCheck(alSourceUnqueueBuffers(source, kNrBuffersStreaming, buffers.data()));
|
alCheck(
|
||||||
|
alSourceUnqueueBuffers(source, kNrBuffersStreaming, buffers.data()));
|
||||||
alCheck(alDeleteBuffers(kNrBuffersStreaming, buffers.data()));
|
alCheck(alDeleteBuffers(kNrBuffersStreaming, buffers.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoundBufferStreamed::bufferData(SoundSource &soundSource) {
|
bool SoundBufferStreamed::bufferData(SoundSource &soundSource) {
|
||||||
|
std::lock_guard<std::mutex> lock(soundSource.mutex);
|
||||||
|
|
||||||
/* Rewind the source position and clear the buffer queue */
|
/* Rewind the source position and clear the buffer queue */
|
||||||
alCheck(alSourceRewind(source));
|
alCheck(alSourceRewind(source));
|
||||||
alCheck(alSourcei(source, AL_BUFFER, 0));
|
alCheck(alSourcei(source, AL_BUFFER, 0));
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(soundSource.mutex);
|
|
||||||
/* Fill the buffer queue */
|
/* Fill the buffer queue */
|
||||||
for (auto i = 0u; i < buffers.size() &&
|
for (auto i = 0u; i < buffers.size() &&
|
||||||
streamedData * kSizeOfChunk < soundSource.data.size();
|
streamedData * kSizeOfChunk < soundSource.data.size();
|
||||||
@ -52,24 +54,31 @@ bool SoundBufferStreamed::bufferData(SoundSource &soundSource) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SoundBufferStreamed::play() {
|
void SoundBufferStreamed::play() {
|
||||||
alSourcePlay(source);
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
||||||
running = true;
|
alSourcePlay(source);
|
||||||
|
|
||||||
|
running = true;
|
||||||
|
}
|
||||||
loadingThread = std::async(std::launch::async,
|
loadingThread = std::async(std::launch::async,
|
||||||
&SoundBufferStreamed::updateBuffers, this);
|
&SoundBufferStreamed::updateBuffers, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundBufferStreamed::updateBuffers() {
|
void SoundBufferStreamed::updateBuffers() {
|
||||||
while (running) {
|
while (true) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
||||||
|
if (!running) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ALint processed, state;
|
ALint processed, state;
|
||||||
|
|
||||||
/* Get relevant source info */
|
/* Get relevant source info */
|
||||||
alCheck(alGetSourcei(source, AL_SOURCE_STATE, &state));
|
alCheck(alGetSourcei(source, AL_SOURCE_STATE, &state));
|
||||||
alCheck(alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed));
|
alCheck(alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed));
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
|
||||||
bool bufferedData = false;
|
bool bufferedData = false;
|
||||||
|
|
||||||
/* Unqueue and handle each processed buffer */
|
/* Unqueue and handle each processed buffer */
|
||||||
@ -110,3 +119,14 @@ void SoundBufferStreamed::updateBuffers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SoundBufferStreamed::pause() {
|
||||||
|
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
||||||
|
running = false;
|
||||||
|
alCheck(alSourcePause(source));
|
||||||
|
}
|
||||||
|
void SoundBufferStreamed::stop() {
|
||||||
|
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
||||||
|
running = false;
|
||||||
|
alCheck(alSourceStop(source));
|
||||||
|
}
|
||||||
|
@ -14,7 +14,9 @@ struct SoundBufferStreamed : public SoundBuffer {
|
|||||||
~SoundBufferStreamed() override;
|
~SoundBufferStreamed() override;
|
||||||
bool bufferData(SoundSource& soundSource) final;
|
bool bufferData(SoundSource& soundSource) final;
|
||||||
|
|
||||||
virtual void play() final;
|
void play() final;
|
||||||
|
void pause() final;
|
||||||
|
void stop() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SoundSource* soundSource = nullptr;
|
SoundSource* soundSource = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user