1
0
Fork 0

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:
Robbert van der Helm 2022-02-01 17:01:05 +01:00
parent 459175b470
commit 3a1fbed4c3
3 changed files with 8 additions and 7 deletions
src

View file

@ -83,6 +83,6 @@ where
/// Something that can execute tasks of type `T`. /// Something that can execute tasks of type `T`.
pub(crate) trait MainThreadExecutor<T>: Send + Sync { pub(crate) trait MainThreadExecutor<T>: Send + Sync {
/// Execute a task on the current thread. /// Execute a task on the current thread. This shoudl only be called from the main thread.
fn execute(&self, task: T); unsafe fn execute(&self, task: T);
} }

View file

@ -85,7 +85,7 @@ where
if self.is_main_thread() { if self.is_main_thread() {
match self.executor.upgrade() { match self.executor.upgrade() {
Some(e) => { Some(e) => {
e.execute(task); unsafe { e.execute(task) };
true true
} }
None => { None => {
@ -125,7 +125,7 @@ where
loop { loop {
match receiver.recv() { match receiver.recv() {
Ok(Message::Task(task)) => match executor.upgrade() { Ok(Message::Task(task)) => match executor.upgrade() {
Some(e) => e.execute(task), Some(e) => unsafe { e.execute(task) },
None => { None => {
nih_log!("Received a new task but the executor is no longer alive, shutting down worker"); nih_log!("Received a new task but the executor is no longer alive, shutting down worker");
return; return;

View file

@ -274,7 +274,8 @@ impl<P: Plugin> Wrapper<'_, P> {
} }
impl<P: Plugin> MainThreadExecutor<Task> for WrapperInner<'_, 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 // 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 // `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 // 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). // then).
match task { match task {
Task::TriggerRestart(flags) => match &*self.component_handler.read() { Task::TriggerRestart(flags) => match &*self.component_handler.read() {
Some(handler) => unsafe { Some(handler) => {
handler.restart_component(flags); handler.restart_component(flags);
}, }
None => nih_debug_assert_failure!("Component handler not yet set"), None => nih_debug_assert_failure!("Component handler not yet set"),
}, },
} }