From 935bf6f7f385cb8e4ef1a689f048e0f4333d0607 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 6 Jan 2023 16:03:48 +0100 Subject: [PATCH] Fix allocation failures in BackgroundThread --- src/event_loop/background_thread.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/event_loop/background_thread.rs b/src/event_loop/background_thread.rs index 2c1716d4..fce559cc 100644 --- a/src/event_loop/background_thread.rs +++ b/src/event_loop/background_thread.rs @@ -8,6 +8,7 @@ use std::sync::{Arc, Weak}; use std::thread::{self, JoinHandle}; use super::MainThreadExecutor; +use crate::util::permit_alloc; /// See the module's documentation. This is a slimmed down version of the `LinuxEventLoop` that can /// be used with other OS and plugin format specific event loop implementations. @@ -52,7 +53,9 @@ where } pub fn schedule(&self, task: T) -> bool { - self.tasks_sender.try_send(Message::Task(task)).is_ok() + // NOTE: This may check the current thread ID, which involves an allocation whenever this + // first happens on a new thread because of the way thread local storage works + permit_alloc(|| self.tasks_sender.try_send(Message::Task(task)).is_ok()) } }