chore: move event loop recreation check into backends themselves

This commit is contained in:
Mads Marquart 2025-05-26 06:48:52 +02:00 committed by GitHub
parent 5f2c7350e9
commit 8ad016362a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 64 additions and 25 deletions

View file

@ -6,7 +6,7 @@ use std::cell::Cell;
use std::ffi::c_void;
use std::os::windows::io::{AsRawHandle as _, FromRawHandle as _, OwnedHandle, RawHandle};
use std::rc::Rc;
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use std::sync::{Arc, LazyLock, Mutex, MutexGuard};
use std::time::{Duration, Instant};
use std::{fmt, mem, panic, ptr};
@ -195,6 +195,12 @@ impl EventLoop {
pub fn new(
attributes: &mut PlatformSpecificEventLoopAttributes,
) -> Result<Self, EventLoopError> {
static EVENT_LOOP_CREATED: AtomicBool = AtomicBool::new(false);
if EVENT_LOOP_CREATED.swap(true, Ordering::Relaxed) {
// For better cross-platformness.
return Err(EventLoopError::RecreationAttempt);
}
let thread_id = unsafe { GetCurrentThreadId() };
if !attributes.any_thread && thread_id != main_thread_id() {