1
0
Fork 0

Don't require Arcs for ProcessContext

It makes more sense to pass this as a reference, so the plugin cannot do
weird things with it.
This commit is contained in:
Robbert van der Helm 2022-01-31 23:47:54 +01:00
parent 22995df7ea
commit f009384c2f
2 changed files with 9 additions and 11 deletions

View file

@ -31,17 +31,15 @@ pub(crate) const TASK_QUEUE_CAPACITY: usize = 512;
/// General callbacks the plugin can make during its lifetime. This is passed to the plugin during /// General callbacks the plugin can make during its lifetime. This is passed to the plugin during
/// [Plugin::initialize]. /// [Plugin::initialize].
/// //
/// # Safety // # Safety
/// //
/// This context is passed to be stored by the plugin, and it may thus not outlive the wrapper. // The implementing wrapper needs to be able to handle concurrent requests, and it should perform
/// Hence the use of reference counted smart pointers. The implementing wrapper needs to be able to // the actual callback within [MainThreadQueue::do_maybe_async].
/// handle concurrent requests, and it should perform the actual callback within pub trait ProcessContext {
/// [MainThreadQueue::do_maybe_async].
pub unsafe trait ProcessContext {
/// Update the current latency of the plugin. If the plugin is currently processing audio, then /// Update the current latency of the plugin. If the plugin is currently processing audio, then
/// this may cause audio playback to be restarted. /// this may cause audio playback to be restarted.
fn set_latency_samples(self: &Arc<Self>, samples: u32); fn set_latency_samples(&self, samples: u32);
} }
/// A trait describing the functionality of the platform-specific event loop that can execute tasks /// A trait describing the functionality of the platform-specific event loop that can execute tasks

View file

@ -263,8 +263,8 @@ impl<P: Plugin> MainThreadExecutor<Task> for WrapperInner<'_, P> {
} }
} }
unsafe impl<P: Plugin> ProcessContext for WrapperInner<'_, P> { impl<P: Plugin> ProcessContext for WrapperInner<'_, P> {
fn set_latency_samples(self: &Arc<Self>, samples: u32) { fn set_latency_samples(&self, samples: u32) {
self.current_latency.store(samples, Ordering::SeqCst); self.current_latency.store(samples, Ordering::SeqCst);
let task_posted = unsafe { self.event_loop.read().assume_init_ref() }.do_maybe_async( let task_posted = unsafe { self.event_loop.read().assume_init_ref() }.do_maybe_async(
Task::TriggerRestart(vst3_sys::vst::RestartFlags::kLatencyChanged as u32), Task::TriggerRestart(vst3_sys::vst::RestartFlags::kLatencyChanged as u32),