Mark MainThreadExecutor::execute as unsafe
This should only be called from the main thread. Otherwise the API's threading guarantees will not be upheld.
This commit is contained in:
parent
459175b470
commit
3a1fbed4c3
3 changed files with 8 additions and 7 deletions
|
@ -83,6 +83,6 @@ where
|
|||
|
||||
/// Something that can execute tasks of type `T`.
|
||||
pub(crate) trait MainThreadExecutor<T>: Send + Sync {
|
||||
/// Execute a task on the current thread.
|
||||
fn execute(&self, task: T);
|
||||
/// Execute a task on the current thread. This shoudl only be called from the main thread.
|
||||
unsafe fn execute(&self, task: T);
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ where
|
|||
if self.is_main_thread() {
|
||||
match self.executor.upgrade() {
|
||||
Some(e) => {
|
||||
e.execute(task);
|
||||
unsafe { e.execute(task) };
|
||||
true
|
||||
}
|
||||
None => {
|
||||
|
@ -125,7 +125,7 @@ where
|
|||
loop {
|
||||
match receiver.recv() {
|
||||
Ok(Message::Task(task)) => match executor.upgrade() {
|
||||
Some(e) => e.execute(task),
|
||||
Some(e) => unsafe { e.execute(task) },
|
||||
None => {
|
||||
nih_log!("Received a new task but the executor is no longer alive, shutting down worker");
|
||||
return;
|
||||
|
|
|
@ -274,7 +274,8 @@ impl<P: Plugin> Wrapper<'_, P> {
|
|||
}
|
||||
|
||||
impl<P: Plugin> MainThreadExecutor<Task> for WrapperInner<'_, P> {
|
||||
fn execute(&self, task: Task) {
|
||||
unsafe fn execute(&self, task: Task) {
|
||||
// This function is always called from the main thread
|
||||
// TODO: When we add GUI resizing and context menus, this should propagate those events to
|
||||
// `IRunLoop` on Linux to keep REAPER happy. That does mean a double spool, but we can
|
||||
// come up with a nicer solution to handle that later (can always add a separate
|
||||
|
@ -282,9 +283,9 @@ impl<P: Plugin> MainThreadExecutor<Task> for WrapperInner<'_, P> {
|
|||
// then).
|
||||
match task {
|
||||
Task::TriggerRestart(flags) => match &*self.component_handler.read() {
|
||||
Some(handler) => unsafe {
|
||||
Some(handler) => {
|
||||
handler.restart_component(flags);
|
||||
},
|
||||
}
|
||||
None => nih_debug_assert_failure!("Component handler not yet set"),
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue