mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Final optimizations and dependency cleanup for mlua-luau-scheduler
This commit is contained in:
parent
d425d2568a
commit
9c9b90d70d
12 changed files with 29 additions and 28 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1992,8 +1992,6 @@ dependencies = [
|
||||||
"async-fs",
|
"async-fs",
|
||||||
"async-io",
|
"async-io",
|
||||||
"blocking",
|
"blocking",
|
||||||
"concurrent-queue",
|
|
||||||
"event-listener",
|
|
||||||
"futures-lite",
|
"futures-lite",
|
||||||
"mlua",
|
"mlua",
|
||||||
"rustc-hash 2.1.1",
|
"rustc-hash 2.1.1",
|
||||||
|
|
|
@ -18,8 +18,6 @@ workspace = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-executor = "1.13"
|
async-executor = "1.13"
|
||||||
blocking = "1.6"
|
blocking = "1.6"
|
||||||
concurrent-queue = "2.5"
|
|
||||||
event-listener = "5.4"
|
|
||||||
futures-lite = "2.6"
|
futures-lite = "2.6"
|
||||||
rustc-hash = "2.1"
|
rustc-hash = "2.1"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
|
5
crates/mlua-luau-scheduler/src/events/mod.rs
Normal file
5
crates/mlua-luau-scheduler/src/events/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
mod multi;
|
||||||
|
mod once;
|
||||||
|
|
||||||
|
pub(crate) use self::multi::MultiEvent;
|
||||||
|
pub(crate) use self::once::OnceEvent;
|
|
@ -8,10 +8,10 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Internal state for queue events.
|
Internal state for events.
|
||||||
*/
|
*/
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct QueueEventState {
|
struct MultiEventState {
|
||||||
generation: Cell<u64>,
|
generation: Cell<u64>,
|
||||||
wakers: RefCell<Vec<Waker>>,
|
wakers: RefCell<Vec<Waker>>,
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@ struct QueueEventState {
|
||||||
A single-threaded event signal that can be notified multiple times.
|
A single-threaded event signal that can be notified multiple times.
|
||||||
*/
|
*/
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub(crate) struct QueueEvent {
|
pub(crate) struct MultiEvent {
|
||||||
state: Rc<QueueEventState>,
|
state: Rc<MultiEventState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QueueEvent {
|
impl MultiEvent {
|
||||||
/**
|
/**
|
||||||
Creates a new event.
|
Creates a new event.
|
||||||
*/
|
*/
|
||||||
|
@ -51,8 +51,8 @@ impl QueueEvent {
|
||||||
/**
|
/**
|
||||||
Creates a listener that implements `Future` and resolves when `notify` is called.
|
Creates a listener that implements `Future` and resolves when `notify` is called.
|
||||||
*/
|
*/
|
||||||
pub fn listen(&self) -> QueueListener {
|
pub fn listen(&self) -> MultiListener {
|
||||||
QueueListener {
|
MultiListener {
|
||||||
state: self.state.clone(),
|
state: self.state.clone(),
|
||||||
generation: self.state.generation.get(),
|
generation: self.state.generation.get(),
|
||||||
}
|
}
|
||||||
|
@ -63,12 +63,12 @@ impl QueueEvent {
|
||||||
A listener future that resolves when the corresponding [`QueueEvent`] is notified.
|
A listener future that resolves when the corresponding [`QueueEvent`] is notified.
|
||||||
*/
|
*/
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct QueueListener {
|
pub(crate) struct MultiListener {
|
||||||
state: Rc<QueueEventState>,
|
state: Rc<MultiEventState>,
|
||||||
generation: u64,
|
generation: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Future for QueueListener {
|
impl Future for MultiListener {
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
|
@ -88,4 +88,4 @@ impl Future for QueueListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Unpin for QueueListener {}
|
impl Unpin for MultiListener {}
|
|
@ -1,24 +1,24 @@
|
||||||
use std::{cell::Cell, rc::Rc};
|
use std::{cell::Cell, rc::Rc};
|
||||||
|
|
||||||
use event_listener::Event;
|
use crate::events::OnceEvent;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct Exit {
|
pub(crate) struct Exit {
|
||||||
code: Rc<Cell<Option<u8>>>,
|
code: Rc<Cell<Option<u8>>>,
|
||||||
event: Rc<Event>,
|
event: OnceEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Exit {
|
impl Exit {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
code: Rc::new(Cell::new(None)),
|
code: Rc::new(Cell::new(None)),
|
||||||
event: Rc::new(Event::new()),
|
event: OnceEvent::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set(&self, code: u8) {
|
pub fn set(&self, code: u8) {
|
||||||
self.code.set(Some(code));
|
self.code.set(Some(code));
|
||||||
self.event.notify(usize::MAX);
|
self.event.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self) -> Option<u8> {
|
pub fn get(&self) -> Option<u8> {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#![allow(clippy::cargo_common_metadata)]
|
#![allow(clippy::cargo_common_metadata)]
|
||||||
|
|
||||||
mod error_callback;
|
mod error_callback;
|
||||||
|
mod events;
|
||||||
mod exit;
|
mod exit;
|
||||||
mod functions;
|
mod functions;
|
||||||
mod queue;
|
mod queue;
|
||||||
|
|
|
@ -2,20 +2,20 @@ use std::{cell::RefCell, mem, pin::Pin, rc::Rc};
|
||||||
|
|
||||||
use futures_lite::prelude::*;
|
use futures_lite::prelude::*;
|
||||||
|
|
||||||
use super::event::QueueEvent;
|
use crate::events::MultiEvent;
|
||||||
|
|
||||||
pub type LocalBoxFuture<'fut> = Pin<Box<dyn Future<Output = ()> + 'fut>>;
|
pub type LocalBoxFuture<'fut> = Pin<Box<dyn Future<Output = ()> + 'fut>>;
|
||||||
|
|
||||||
struct FuturesQueueInner<'fut> {
|
struct FuturesQueueInner<'fut> {
|
||||||
queue: RefCell<Vec<LocalBoxFuture<'fut>>>,
|
queue: RefCell<Vec<LocalBoxFuture<'fut>>>,
|
||||||
event: QueueEvent,
|
event: MultiEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FuturesQueueInner<'_> {
|
impl FuturesQueueInner<'_> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
queue: RefCell::new(Vec::new()),
|
queue: RefCell::new(Vec::new()),
|
||||||
event: QueueEvent::new(),
|
event: MultiEvent::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
mod deferred;
|
mod deferred;
|
||||||
mod event;
|
|
||||||
mod futures;
|
mod futures;
|
||||||
mod spawned;
|
mod spawned;
|
||||||
mod threads;
|
mod threads;
|
||||||
|
|
|
@ -6,19 +6,19 @@ use mlua::prelude::*;
|
||||||
|
|
||||||
use crate::{threads::ThreadId, traits::IntoLuaThread};
|
use crate::{threads::ThreadId, traits::IntoLuaThread};
|
||||||
|
|
||||||
use super::event::QueueEvent;
|
use crate::events::MultiEvent;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct ThreadQueueInner {
|
struct ThreadQueueInner {
|
||||||
queue: RefCell<Vec<(LuaThread, LuaMultiValue)>>,
|
queue: RefCell<Vec<(LuaThread, LuaMultiValue)>>,
|
||||||
event: QueueEvent,
|
event: MultiEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThreadQueueInner {
|
impl ThreadQueueInner {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
queue: RefCell::new(Vec::new()),
|
queue: RefCell::new(Vec::new()),
|
||||||
event: QueueEvent::new(),
|
event: MultiEvent::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ use std::{cell::RefCell, rc::Rc};
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use super::{event::OnceEvent, id::ThreadId};
|
use super::id::ThreadId;
|
||||||
|
use crate::events::OnceEvent;
|
||||||
|
|
||||||
struct ThreadEvent {
|
struct ThreadEvent {
|
||||||
result: Option<LuaResult<LuaMultiValue>>,
|
result: Option<LuaResult<LuaMultiValue>>,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
mod event;
|
|
||||||
mod id;
|
mod id;
|
||||||
mod map;
|
mod map;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue