1
0
Fork 0

Fix allocation error from thread locals

This commit is contained in:
Robbert van der Helm 2022-03-08 14:07:29 +01:00
parent be39e19365
commit b9412657c1
3 changed files with 12 additions and 3 deletions

View file

@ -8,6 +8,7 @@ use std::thread::{self, JoinHandle, ThreadId};
use super::{EventLoop, MainThreadExecutor};
use crate::nih_log;
use crate::util::permit_alloc;
/// See [`EventLoop`][super::EventLoop].
#[cfg_attr(
@ -83,7 +84,9 @@ where
}
fn is_main_thread(&self) -> bool {
thread::current().id() == self.main_thread_id
// FIXME: `thread::current()` may allocate the first time it's called, is there a safe
// nonallocating version of this without using huge OS-specific libraries?
permit_alloc(|| thread::current().id() == self.main_thread_id)
}
}

View file

@ -20,6 +20,7 @@ use windows::Win32::UI::WindowsAndMessaging::{
use super::{EventLoop, MainThreadExecutor};
use crate::nih_log;
use crate::util::permit_alloc;
/// The custom message ID for our notify event. If the hidden event loop window receives this, then
/// it knows it should start polling events.
@ -160,7 +161,9 @@ where
}
fn is_main_thread(&self) -> bool {
thread::current().id() == self.main_thread_id
// FIXME: `thread::current()` may allocate the first time it's called, is there a safe
// nonallocating version of this without using huge OS-specific libraries?
permit_alloc(|| thread::current().id() == self.main_thread_id)
}
}

View file

@ -66,6 +66,7 @@ use crate::param::internals::ParamPtr;
use crate::plugin::{
BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, ProcessStatus,
};
use crate::util::permit_alloc;
use crate::wrapper::state;
use crate::wrapper::util::{hash_param_id, process_wrapper, strlcpy};
@ -255,7 +256,9 @@ impl<P: ClapPlugin> EventLoop<Task, Wrapper<P>> for Wrapper<P> {
// check if this is the same thread as the one that created the plugin instance.
match &*self.host_thread_check.borrow() {
Some(thread_check) => unsafe { (thread_check.is_main_thread)(&*self.host_callback) },
None => thread::current().id() == self.main_thread_id,
// FIXME: `thread::current()` may allocate the first time it's called, is there a safe
// nonallocating version of this without using huge OS-specific libraries?
None => permit_alloc(|| thread::current().id() == self.main_thread_id),
}
}
}