Fix allocation error from thread locals
This commit is contained in:
parent
be39e19365
commit
b9412657c1
3 changed files with 12 additions and 3 deletions
|
@ -8,6 +8,7 @@ use std::thread::{self, JoinHandle, ThreadId};
|
||||||
|
|
||||||
use super::{EventLoop, MainThreadExecutor};
|
use super::{EventLoop, MainThreadExecutor};
|
||||||
use crate::nih_log;
|
use crate::nih_log;
|
||||||
|
use crate::util::permit_alloc;
|
||||||
|
|
||||||
/// See [`EventLoop`][super::EventLoop].
|
/// See [`EventLoop`][super::EventLoop].
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
|
@ -83,7 +84,9 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_main_thread(&self) -> bool {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ use windows::Win32::UI::WindowsAndMessaging::{
|
||||||
|
|
||||||
use super::{EventLoop, MainThreadExecutor};
|
use super::{EventLoop, MainThreadExecutor};
|
||||||
use crate::nih_log;
|
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
|
/// The custom message ID for our notify event. If the hidden event loop window receives this, then
|
||||||
/// it knows it should start polling events.
|
/// it knows it should start polling events.
|
||||||
|
@ -160,7 +161,9 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_main_thread(&self) -> bool {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,7 @@ use crate::param::internals::ParamPtr;
|
||||||
use crate::plugin::{
|
use crate::plugin::{
|
||||||
BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, ProcessStatus,
|
BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, ProcessStatus,
|
||||||
};
|
};
|
||||||
|
use crate::util::permit_alloc;
|
||||||
use crate::wrapper::state;
|
use crate::wrapper::state;
|
||||||
use crate::wrapper::util::{hash_param_id, process_wrapper, strlcpy};
|
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.
|
// check if this is the same thread as the one that created the plugin instance.
|
||||||
match &*self.host_thread_check.borrow() {
|
match &*self.host_thread_check.borrow() {
|
||||||
Some(thread_check) => unsafe { (thread_check.is_main_thread)(&*self.host_callback) },
|
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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue