Skip to content

Commit 2affe3a

Browse files
committed
Make writes to mManagedBuffer safe
- Prevent race conditions between thread mode updates and IRQ mode updates - Potential fix for microsoft/pxt-microbit#6492
1 parent 5365759 commit 2affe3a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

source/SoundOutputPin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ void SoundOutputPin::update()
190190
*/
191191
void SoundOutputPin::updateOutputBuffer(bool all)
192192
{
193+
target_disable_irq();
194+
193195
uint8_t *bufferEnd = outputBuffer.getBytes() + outputBuffer.length();
194196
uint8_t *endPosition = all ? bufferEnd : outputBuffer.getBytes() + min(outputBuffer.length(), (int) ((1000.0f / SOUND_OUTPUT_PIN_SAMPLE_RATE) * (timeOfLastUpdate - timeOfLastPull)));
195197

@@ -229,6 +231,8 @@ void SoundOutputPin::updateOutputBuffer(bool all)
229231
// Snapshot the current sound parameters in case they are changed in flight
230232
_periodUs = periodUs;
231233
_value = value;
234+
235+
target_enable_irq();
232236
}
233237

234238
/**

0 commit comments

Comments
 (0)