Browse Source

Made AudioBuffer::isClear atomic to fix a potential data race when used from multiple threads

tags/2021-05-28
ed 6 years ago
parent
commit
ce20ab8a3b
1 changed files with 3 additions and 3 deletions
  1. +3
    -3
      modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h

+ 3
- 3
modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h View File

@@ -180,7 +180,7 @@ public:
size (other.size), size (other.size),
allocatedBytes (other.allocatedBytes), allocatedBytes (other.allocatedBytes),
allocatedData (std::move (other.allocatedData)), allocatedData (std::move (other.allocatedData)),
isClear (other.isClear)
isClear (other.isClear.load())
{ {
if (numChannels < (int) numElementsInArray (preallocatedChannelSpace)) if (numChannels < (int) numElementsInArray (preallocatedChannelSpace))
{ {
@@ -206,7 +206,7 @@ public:
size = other.size; size = other.size;
allocatedBytes = other.allocatedBytes; allocatedBytes = other.allocatedBytes;
allocatedData = std::move (other.allocatedData); allocatedData = std::move (other.allocatedData);
isClear = other.isClear;
isClear = other.isClear.load();
if (numChannels < (int) numElementsInArray (preallocatedChannelSpace)) if (numChannels < (int) numElementsInArray (preallocatedChannelSpace))
{ {
@@ -1071,7 +1071,7 @@ private:
Type** channels; Type** channels;
HeapBlock<char, true> allocatedData; HeapBlock<char, true> allocatedData;
Type* preallocatedChannelSpace[32]; Type* preallocatedChannelSpace[32];
bool isClear = false;
std::atomic<bool> isClear { false };
void allocateData() void allocateData()
{ {


Loading…
Cancel
Save