Skip to content

Commit 61ba7c0

Browse files
committed
AudioBufferSourceNode: Replace needless atomic with Cell
1 parent 8b5b963 commit 61ba7c0

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/node/audio_buffer_source.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::any::Any;
2-
use std::cell::{OnceCell, RefCell};
3-
use std::sync::atomic::{AtomicBool, Ordering};
2+
use std::cell::{Cell, OnceCell, RefCell};
43

54
use crate::buffer::AudioBuffer;
65
use crate::context::{AudioContextRegistration, AudioParamId, BaseAudioContext};
@@ -104,7 +103,7 @@ pub struct AudioBufferSourceNode {
104103
playback_rate: AudioParam, // has constraints, no a-rate
105104
loop_state: RefCell<LoopState>,
106105
buffer: OnceCell<AudioBuffer>,
107-
source_started: AtomicBool,
106+
source_started: Cell<bool>,
108107
}
109108

110109
impl AudioNode for AudioBufferSourceNode {
@@ -141,9 +140,10 @@ impl AudioScheduledSourceNode for AudioBufferSourceNode {
141140
}
142141

143142
fn stop_at(&self, when: f64) {
144-
if !self.source_started.load(Ordering::SeqCst) {
145-
panic!("InvalidStateError cannot stop before start");
146-
}
143+
assert!(
144+
self.source_started.get(),
145+
"InvalidStateError cannot stop before start"
146+
);
147147

148148
self.registration.post_message(ControlMessage::Stop(when));
149149
}
@@ -212,7 +212,7 @@ impl AudioBufferSourceNode {
212212
playback_rate: pr_param,
213213
loop_state: RefCell::new(loop_state),
214214
buffer: OnceCell::new(),
215-
source_started: AtomicBool::new(false),
215+
source_started: Cell::new(false),
216216
};
217217

218218
if let Some(buf) = buffer {
@@ -238,9 +238,11 @@ impl AudioBufferSourceNode {
238238
///
239239
/// Panics if the source was already started
240240
pub fn start_at_with_offset_and_duration(&self, start: f64, offset: f64, duration: f64) {
241-
if self.source_started.swap(true, Ordering::SeqCst) {
242-
panic!("InvalidStateError: Cannot call `start` twice");
243-
}
241+
assert!(
242+
!self.source_started.get(),
243+
"InvalidStateError: Cannot call `start` twice"
244+
);
245+
self.source_started.set(true);
244246

245247
let control = ControlMessage::StartWithOffsetAndDuration(start, offset, duration);
246248
self.registration.post_message(control);

0 commit comments

Comments
 (0)