revert: bring back task abstraction
This commit is contained in:
@@ -34,7 +34,7 @@ wayland = [
|
||||
"dep:wgpu-hal",
|
||||
"dep:ash",
|
||||
]
|
||||
profile_tokio = ["dep:console-subscriber"]
|
||||
profile_tokio = ["dep:console-subscriber", "tokio/tracing"]
|
||||
profile_app = [
|
||||
"dep:tracing-tracy",
|
||||
"bevy/trace_tracy",
|
||||
@@ -101,7 +101,7 @@ toml = "0.9.7"
|
||||
# mathy stuffs
|
||||
glam = { version = "0.29.0", features = ["mint", "serde"] }
|
||||
mint = "0.5.9"
|
||||
tokio = { version = "1.39.2", features = ["rt-multi-thread", "signal", "time", "tracing"] }
|
||||
tokio = { version = "1.39.2", features = ["rt-multi-thread", "signal", "time"] }
|
||||
|
||||
# bevy
|
||||
bevy = { version = "0.16", default-features = false, features = [
|
||||
|
||||
@@ -3,7 +3,7 @@ use super::{
|
||||
scenegraph::Scenegraph,
|
||||
};
|
||||
use crate::{
|
||||
core::registry::OwnedRegistry,
|
||||
core::{registry::OwnedRegistry, task},
|
||||
nodes::{
|
||||
Node, audio, drawable, fields, input, items,
|
||||
root::{ClientState, Root},
|
||||
@@ -143,11 +143,9 @@ impl Client {
|
||||
})
|
||||
.unwrap_or_else(|| "??".to_string());
|
||||
let _ = client.dispatch_join_handle.get_or_init(|| {
|
||||
tokio::task::Builder::new()
|
||||
.name(&format!(
|
||||
"Stardust client \"{exe_printable}\" dispatch, pid={pid_printable}",
|
||||
))
|
||||
.spawn({
|
||||
task::new(
|
||||
|| format!("Stardust client \"{exe_printable}\" dispatch, pid={pid_printable}"),
|
||||
{
|
||||
let client = client.clone();
|
||||
async move {
|
||||
loop {
|
||||
@@ -157,15 +155,14 @@ impl Client {
|
||||
let _ = message_time_tx.send(Instant::now());
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap()
|
||||
},
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
let _ = client.flush_join_handle.get_or_init(|| {
|
||||
tokio::task::Builder::new()
|
||||
.name(&format!(
|
||||
"Stardust client \"{exe_printable}\" flush, pid={pid_printable}",
|
||||
))
|
||||
.spawn({
|
||||
task::new(
|
||||
|| format!("Stardust client \"{exe_printable}\" flush, pid={pid_printable}"),
|
||||
{
|
||||
let client = client.clone();
|
||||
async move {
|
||||
loop {
|
||||
@@ -174,8 +171,9 @@ impl Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap()
|
||||
},
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
Ok(client)
|
||||
|
||||
@@ -8,3 +8,4 @@ pub mod error;
|
||||
pub mod registry;
|
||||
pub mod resource;
|
||||
pub mod scenegraph;
|
||||
pub mod task;
|
||||
|
||||
21
src/core/task.rs
Normal file
21
src/core/task.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use std::future::Future;
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub fn new<
|
||||
F: FnOnce() -> S,
|
||||
S: AsRef<str>,
|
||||
A: Future<Output = O> + Send + 'static,
|
||||
O: Send + 'static,
|
||||
>(
|
||||
name_fn: F,
|
||||
async_future: A,
|
||||
) -> std::io::Result<JoinHandle<O>> {
|
||||
#[cfg(not(feature = "profile_tokio"))]
|
||||
let result = Ok(tokio::task::spawn(async_future));
|
||||
#[cfg(feature = "profile_tokio")]
|
||||
let result = tokio::task::Builder::new()
|
||||
.name(name_fn().as_ref())
|
||||
.spawn(async_future);
|
||||
result
|
||||
}
|
||||
23
src/main.rs
23
src/main.rs
@@ -51,6 +51,7 @@ use bevy_mod_xr::session::{XrFirst, XrHandleEvents, XrSessionPlugin};
|
||||
use clap::Parser;
|
||||
use core::client::{Client, tick_internal_client};
|
||||
use core::entity_handle::EntityHandlePlugin;
|
||||
use core::task;
|
||||
use directories::ProjectDirs;
|
||||
use nodes::audio::AudioNodePlugin;
|
||||
use nodes::drawable::lines::LinesNodePlugin;
|
||||
@@ -167,19 +168,17 @@ async fn main() -> Result<AppExit, JoinError> {
|
||||
);
|
||||
let socket = UnixListener::bind(locked_socket.socket_path)
|
||||
.expect("Couldn't spawn stardust server at {socket_path}");
|
||||
tokio::task::Builder::new()
|
||||
.name("Stardust client accept loop")
|
||||
.spawn(async move {
|
||||
loop {
|
||||
let Ok((stream, _)) = socket.accept().await else {
|
||||
continue;
|
||||
};
|
||||
if let Err(e) = Client::from_connection(stream) {
|
||||
error!(?e, "Unable to create client from connection");
|
||||
}
|
||||
task::new(|| "Stardust socket accept loop", async move {
|
||||
loop {
|
||||
let Ok((stream, _)) = socket.accept().await else {
|
||||
continue;
|
||||
};
|
||||
if let Err(e) = Client::from_connection(stream) {
|
||||
error!(?e, "Unable to create client from connection");
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
info!("Init client join loop");
|
||||
|
||||
let project_dirs = ProjectDirs::from("", "", "stardust");
|
||||
|
||||
@@ -9,7 +9,6 @@ mod viewporter;
|
||||
mod vulkano_data;
|
||||
mod xdg;
|
||||
|
||||
use crate::BevyMaterial;
|
||||
use crate::core::error::ServerError;
|
||||
use crate::core::registry::OwnedRegistry;
|
||||
use crate::nodes::drawable::model::ModelNodeSystemSet;
|
||||
@@ -17,6 +16,7 @@ use crate::wayland::core::seat::SeatMessage;
|
||||
use crate::wayland::core::surface::Surface;
|
||||
use crate::wayland::presentation::MonotonicTimestamp;
|
||||
use crate::wayland::util::ClientExt;
|
||||
use crate::{BevyMaterial, core::task};
|
||||
use bevy::app::{App, Plugin, Update};
|
||||
use bevy::ecs::schedule::IntoScheduleConfigs;
|
||||
use bevy::ecs::system::{Local, Res, ResMut};
|
||||
@@ -257,12 +257,11 @@ impl WaylandClient {
|
||||
.map(|exe| exe.to_string())
|
||||
})
|
||||
.unwrap_or_else(|| "??".to_string());
|
||||
let abort_handle = tokio::task::Builder::new()
|
||||
.name(&format!(
|
||||
"Wayland client \"{exe_printable}\" dispatch, pid={pid_printable}",
|
||||
))
|
||||
.spawn(Self::dispatch_loop(client, message_source))?
|
||||
.abort_handle();
|
||||
let abort_handle = task::new(
|
||||
|| format!("Wayland client \"{exe_printable}\" dispatch, pid={pid_printable}"),
|
||||
Self::dispatch_loop(client, message_source),
|
||||
)?
|
||||
.abort_handle();
|
||||
|
||||
Ok(WaylandClient { abort_handle })
|
||||
}
|
||||
@@ -383,10 +382,11 @@ impl Wayland {
|
||||
let listener = waynest_server::Listener::new_with_path(&socket_path)?;
|
||||
let _ = WAYLAND_DISPLAY.set(listener.socket_path().to_path_buf());
|
||||
|
||||
let abort_handle = tokio::task::Builder::new()
|
||||
.name("Wayland client accept loop")
|
||||
.spawn(Self::handle_wayland_loop(listener))?
|
||||
.abort_handle();
|
||||
let abort_handle = task::new(
|
||||
|| "Wayland socket accept loop",
|
||||
Self::handle_wayland_loop(listener),
|
||||
)?
|
||||
.abort_handle();
|
||||
|
||||
Ok(Self {
|
||||
_lockfile,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::toplevel::Toplevel;
|
||||
use crate::{
|
||||
core::error::Result,
|
||||
core::{error::Result, task},
|
||||
nodes::{
|
||||
drawable::model::ModelPart,
|
||||
items::panel::{
|
||||
@@ -137,14 +137,12 @@ impl Backend for XdgBackend {
|
||||
let Some(seat) = self.seat.upgrade() else {
|
||||
return;
|
||||
};
|
||||
let _ = tokio::task::Builder::new()
|
||||
.name("Apply cursor material")
|
||||
.spawn(async move {
|
||||
let Some(cursor) = seat.cursor_surface().await else {
|
||||
return;
|
||||
};
|
||||
cursor.apply_material(&model_part);
|
||||
});
|
||||
let _ = task::new(|| "Apply cursor material", async move {
|
||||
let Some(cursor) = seat.cursor_surface().await else {
|
||||
return;
|
||||
};
|
||||
cursor.apply_material(&model_part);
|
||||
});
|
||||
}
|
||||
fn apply_surface_material(&self, surface: SurfaceId, model_part: &Arc<ModelPart>) {
|
||||
if let Some(surface) = self.surface_from_id(&surface) {
|
||||
|
||||
Reference in New Issue
Block a user