fix: tokio tasks
This commit is contained in:
@@ -3,7 +3,7 @@ use super::{
|
|||||||
scenegraph::Scenegraph,
|
scenegraph::Scenegraph,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
core::{registry::OwnedRegistry, task},
|
core::registry::OwnedRegistry,
|
||||||
nodes::{
|
nodes::{
|
||||||
Node, audio, drawable, fields, input, items,
|
Node, audio, drawable, fields, input, items,
|
||||||
root::{ClientState, Root},
|
root::{ClientState, Root},
|
||||||
@@ -143,14 +143,11 @@ impl Client {
|
|||||||
})
|
})
|
||||||
.unwrap_or_else(|| "??".to_string());
|
.unwrap_or_else(|| "??".to_string());
|
||||||
let _ = client.dispatch_join_handle.get_or_init(|| {
|
let _ = client.dispatch_join_handle.get_or_init(|| {
|
||||||
task::new(
|
tokio::task::Builder::new()
|
||||||
|| {
|
.name(&format!(
|
||||||
format!(
|
"Stardust client \"{exe_printable}\" dispatch, pid={pid_printable}",
|
||||||
"client dispatch pid={} exe={}",
|
))
|
||||||
&pid_printable, &exe_printable,
|
.spawn({
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
async move {
|
async move {
|
||||||
loop {
|
loop {
|
||||||
@@ -160,14 +157,15 @@ impl Client {
|
|||||||
let _ = message_time_tx.send(Instant::now());
|
let _ = message_time_tx.send(Instant::now());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
)
|
.unwrap()
|
||||||
.unwrap()
|
|
||||||
});
|
});
|
||||||
let _ = client.flush_join_handle.get_or_init(|| {
|
let _ = client.flush_join_handle.get_or_init(|| {
|
||||||
task::new(
|
tokio::task::Builder::new()
|
||||||
|| format!("client flush pid={} exe={}", &pid_printable, &exe_printable,),
|
.name(&format!(
|
||||||
{
|
"Stardust client \"{exe_printable}\" flush, pid={pid_printable}",
|
||||||
|
))
|
||||||
|
.spawn({
|
||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
async move {
|
async move {
|
||||||
loop {
|
loop {
|
||||||
@@ -176,9 +174,8 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
)
|
.unwrap()
|
||||||
.unwrap()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(client)
|
Ok(client)
|
||||||
|
|||||||
@@ -8,4 +8,3 @@ pub mod error;
|
|||||||
pub mod registry;
|
pub mod registry;
|
||||||
pub mod resource;
|
pub mod resource;
|
||||||
pub mod scenegraph;
|
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 clap::Parser;
|
||||||
use core::client::{Client, tick_internal_client};
|
use core::client::{Client, tick_internal_client};
|
||||||
use core::entity_handle::EntityHandlePlugin;
|
use core::entity_handle::EntityHandlePlugin;
|
||||||
use core::task;
|
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use nodes::audio::AudioNodePlugin;
|
use nodes::audio::AudioNodePlugin;
|
||||||
use nodes::drawable::lines::LinesNodePlugin;
|
use nodes::drawable::lines::LinesNodePlugin;
|
||||||
@@ -143,9 +142,7 @@ async fn main() -> Result<AppExit, JoinError> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "profile_tokio")]
|
#[cfg(feature = "profile_tokio")]
|
||||||
let (console_layer, _) = console_subscriber::ConsoleLayer::builder().build();
|
let registry = registry.with(console_subscriber::spawn());
|
||||||
#[cfg(feature = "profile_tokio")]
|
|
||||||
let registry = registry.with(console_layer);
|
|
||||||
|
|
||||||
let log_layer = fmt::Layer::new()
|
let log_layer = fmt::Layer::new()
|
||||||
.with_thread_names(true)
|
.with_thread_names(true)
|
||||||
@@ -170,17 +167,19 @@ async fn main() -> Result<AppExit, JoinError> {
|
|||||||
);
|
);
|
||||||
let socket = UnixListener::bind(locked_socket.socket_path)
|
let socket = UnixListener::bind(locked_socket.socket_path)
|
||||||
.expect("Couldn't spawn stardust server at {socket_path}");
|
.expect("Couldn't spawn stardust server at {socket_path}");
|
||||||
task::new(|| "client join loop", async move {
|
tokio::task::Builder::new()
|
||||||
loop {
|
.name("Stardust client accept loop")
|
||||||
let Ok((stream, _)) = socket.accept().await else {
|
.spawn(async move {
|
||||||
continue;
|
loop {
|
||||||
};
|
let Ok((stream, _)) = socket.accept().await else {
|
||||||
if let Err(e) = Client::from_connection(stream) {
|
continue;
|
||||||
error!(?e, "Unable to create client from connection");
|
};
|
||||||
|
if let Err(e) = Client::from_connection(stream) {
|
||||||
|
error!(?e, "Unable to create client from connection");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
info!("Init client join loop");
|
info!("Init client join loop");
|
||||||
|
|
||||||
let project_dirs = ProjectDirs::from("", "", "stardust");
|
let project_dirs = ProjectDirs::from("", "", "stardust");
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ mod viewporter;
|
|||||||
mod vulkano_data;
|
mod vulkano_data;
|
||||||
mod xdg;
|
mod xdg;
|
||||||
|
|
||||||
|
use crate::BevyMaterial;
|
||||||
use crate::core::error::ServerError;
|
use crate::core::error::ServerError;
|
||||||
use crate::core::registry::OwnedRegistry;
|
use crate::core::registry::OwnedRegistry;
|
||||||
use crate::nodes::drawable::model::ModelNodeSystemSet;
|
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::core::surface::Surface;
|
||||||
use crate::wayland::presentation::MonotonicTimestamp;
|
use crate::wayland::presentation::MonotonicTimestamp;
|
||||||
use crate::wayland::util::ClientExt;
|
use crate::wayland::util::ClientExt;
|
||||||
use crate::{BevyMaterial, core::task};
|
|
||||||
use bevy::app::{App, Plugin, Update};
|
use bevy::app::{App, Plugin, Update};
|
||||||
use bevy::ecs::schedule::IntoScheduleConfigs;
|
use bevy::ecs::schedule::IntoScheduleConfigs;
|
||||||
use bevy::ecs::system::{Local, Res, ResMut};
|
use bevy::ecs::system::{Local, Res, ResMut};
|
||||||
@@ -361,8 +361,10 @@ impl Wayland {
|
|||||||
let listener = waynest_server::Listener::new_with_path(&socket_path)?;
|
let listener = waynest_server::Listener::new_with_path(&socket_path)?;
|
||||||
let _ = WAYLAND_DISPLAY.set(listener.socket_path().to_path_buf());
|
let _ = WAYLAND_DISPLAY.set(listener.socket_path().to_path_buf());
|
||||||
|
|
||||||
let abort_handle =
|
let abort_handle = tokio::task::Builder::new()
|
||||||
task::new(|| "wayland loop", Self::handle_wayland_loop(listener))?.abort_handle();
|
.name("Wayland client accept loop")
|
||||||
|
.spawn(Self::handle_wayland_loop(listener))?
|
||||||
|
.abort_handle();
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
_lockfile,
|
_lockfile,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use super::toplevel::Toplevel;
|
use super::toplevel::Toplevel;
|
||||||
use crate::{
|
use crate::{
|
||||||
core::{error::Result, task},
|
core::error::Result,
|
||||||
nodes::{
|
nodes::{
|
||||||
drawable::model::ModelPart,
|
drawable::model::ModelPart,
|
||||||
items::panel::{
|
items::panel::{
|
||||||
@@ -137,12 +137,14 @@ impl Backend for XdgBackend {
|
|||||||
let Some(seat) = self.seat.upgrade() else {
|
let Some(seat) = self.seat.upgrade() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let _ = task::new(|| "apply cursor material", async move {
|
let _ = tokio::task::Builder::new()
|
||||||
let Some(cursor) = seat.cursor_surface().await else {
|
.name("Apply cursor material")
|
||||||
return;
|
.spawn(async move {
|
||||||
};
|
let Some(cursor) = seat.cursor_surface().await else {
|
||||||
cursor.apply_material(&model_part);
|
return;
|
||||||
});
|
};
|
||||||
|
cursor.apply_material(&model_part);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
fn apply_surface_material(&self, surface: SurfaceId, model_part: &Arc<ModelPart>) {
|
fn apply_surface_material(&self, surface: SurfaceId, model_part: &Arc<ModelPart>) {
|
||||||
if let Some(surface) = self.surface_from_id(&surface) {
|
if let Some(surface) = self.surface_from_id(&surface) {
|
||||||
|
|||||||
Reference in New Issue
Block a user