fix: tokio tasks
This commit is contained in:
@@ -3,7 +3,7 @@ use super::{
|
||||
scenegraph::Scenegraph,
|
||||
};
|
||||
use crate::{
|
||||
core::{registry::OwnedRegistry, task},
|
||||
core::registry::OwnedRegistry,
|
||||
nodes::{
|
||||
Node, audio, drawable, fields, input, items,
|
||||
root::{ClientState, Root},
|
||||
@@ -143,14 +143,11 @@ impl Client {
|
||||
})
|
||||
.unwrap_or_else(|| "??".to_string());
|
||||
let _ = client.dispatch_join_handle.get_or_init(|| {
|
||||
task::new(
|
||||
|| {
|
||||
format!(
|
||||
"client dispatch pid={} exe={}",
|
||||
&pid_printable, &exe_printable,
|
||||
)
|
||||
},
|
||||
{
|
||||
tokio::task::Builder::new()
|
||||
.name(&format!(
|
||||
"Stardust client \"{exe_printable}\" dispatch, pid={pid_printable}",
|
||||
))
|
||||
.spawn({
|
||||
let client = client.clone();
|
||||
async move {
|
||||
loop {
|
||||
@@ -160,14 +157,15 @@ impl Client {
|
||||
let _ = message_time_tx.send(Instant::now());
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.unwrap()
|
||||
});
|
||||
let _ = client.flush_join_handle.get_or_init(|| {
|
||||
task::new(
|
||||
|| format!("client flush pid={} exe={}", &pid_printable, &exe_printable,),
|
||||
{
|
||||
tokio::task::Builder::new()
|
||||
.name(&format!(
|
||||
"Stardust client \"{exe_printable}\" flush, pid={pid_printable}",
|
||||
))
|
||||
.spawn({
|
||||
let client = client.clone();
|
||||
async move {
|
||||
loop {
|
||||
@@ -176,9 +174,8 @@ impl Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
Ok(client)
|
||||
|
||||
@@ -8,4 +8,3 @@ pub mod error;
|
||||
pub mod registry;
|
||||
pub mod resource;
|
||||
pub mod scenegraph;
|
||||
pub mod task;
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
use color_eyre::eyre::Result;
|
||||
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,
|
||||
) -> 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)
|
||||
.map_err(Into::into);
|
||||
result
|
||||
}
|
||||
27
src/main.rs
27
src/main.rs
@@ -51,7 +51,6 @@ 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;
|
||||
@@ -143,9 +142,7 @@ async fn main() -> Result<AppExit, JoinError> {
|
||||
);
|
||||
|
||||
#[cfg(feature = "profile_tokio")]
|
||||
let (console_layer, _) = console_subscriber::ConsoleLayer::builder().build();
|
||||
#[cfg(feature = "profile_tokio")]
|
||||
let registry = registry.with(console_layer);
|
||||
let registry = registry.with(console_subscriber::spawn());
|
||||
|
||||
let log_layer = fmt::Layer::new()
|
||||
.with_thread_names(true)
|
||||
@@ -170,17 +167,19 @@ async fn main() -> Result<AppExit, JoinError> {
|
||||
);
|
||||
let socket = UnixListener::bind(locked_socket.socket_path)
|
||||
.expect("Couldn't spawn stardust server at {socket_path}");
|
||||
task::new(|| "client join 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");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
info!("Init client join loop");
|
||||
|
||||
let project_dirs = ProjectDirs::from("", "", "stardust");
|
||||
|
||||
@@ -9,6 +9,7 @@ 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;
|
||||
@@ -16,7 +17,6 @@ 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};
|
||||
@@ -361,8 +361,10 @@ 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 =
|
||||
task::new(|| "wayland loop", Self::handle_wayland_loop(listener))?.abort_handle();
|
||||
let abort_handle = tokio::task::Builder::new()
|
||||
.name("Wayland client accept loop")
|
||||
.spawn(Self::handle_wayland_loop(listener))?
|
||||
.abort_handle();
|
||||
|
||||
Ok(Self {
|
||||
_lockfile,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::toplevel::Toplevel;
|
||||
use crate::{
|
||||
core::{error::Result, task},
|
||||
core::error::Result,
|
||||
nodes::{
|
||||
drawable::model::ModelPart,
|
||||
items::panel::{
|
||||
@@ -137,12 +137,14 @@ impl Backend for XdgBackend {
|
||||
let Some(seat) = self.seat.upgrade() else {
|
||||
return;
|
||||
};
|
||||
let _ = task::new(|| "apply cursor material", async move {
|
||||
let Some(cursor) = seat.cursor_surface().await else {
|
||||
return;
|
||||
};
|
||||
cursor.apply_material(&model_part);
|
||||
});
|
||||
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);
|
||||
});
|
||||
}
|
||||
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