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

@ -1,5 +1,6 @@
use std::cell::Cell;
use std::collections::VecDeque;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{mpsc, Arc, Mutex};
use std::time::Instant;
use std::{iter, mem, slice};
@ -280,6 +281,12 @@ pub struct EventLoop {
impl EventLoop {
pub fn new(_: &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);
}
// NOTE: Create a channel which can hold only one event to automatically _squash_ user
// events.
let (user_events_sender, user_events_receiver) = mpsc::sync_channel(1);