Selaa lähdekoodia

app: name all spawned threads

darkfi 8 kuukautta sitten
vanhempi
sitoutus
b41eba2b5d

+ 2 - 2
bin/app/src/app/schema/mod.rs

@@ -32,7 +32,7 @@ use crate::{
     scene::{SceneNodePtr, Slot},
     shape,
     ui::{emoji_picker, Layer, Shortcut, VectorArt, VectorShape, Video},
-    util::i18n::I18nBabelFish,
+    util::{i18n::I18nBabelFish, spawn_thread},
 };
 
 mod chat;
@@ -489,7 +489,7 @@ pub async fn make(app: &App, window: SceneNodePtr, i18n_fish: &I18nBabelFish) {
     );
 
     let emoji_meshes2 = emoji_meshes.clone();
-    std::thread::spawn(move || {
+    spawn_thread("load-emojis", move || {
         for i in (0..500).step_by(20) {
             let mut emoji = emoji_meshes2.lock();
             for j in i..(i + 20) {

+ 2 - 2
bin/app/src/text2/mod.rs

@@ -22,7 +22,7 @@ use std::{
     sync::{Arc, OnceLock},
 };
 
-use crate::mesh::Color;
+use crate::{mesh::Color, util::spawn_thread};
 
 pub mod atlas;
 mod editor;
@@ -56,7 +56,7 @@ impl<T> AsyncGlobal<T> {
 pub static TEXT_CTX: AsyncGlobal<TextContext> = AsyncGlobal::new();
 
 pub fn init_txt_ctx() {
-    std::thread::spawn(|| {
+    spawn_thread("init_txt_ctx", || {
         // This is quite slow. It takes 300ms
         let txt_ctx = TextContext::new();
         TEXT_CTX.set(txt_ctx);

+ 3 - 2
bin/app/src/ui/video.rs

@@ -32,7 +32,7 @@ use crate::{
     mesh::{MeshBuilder, MeshInfo, COLOR_WHITE},
     prop::{BatchGuardPtr, PropertyAtomicGuard, PropertyRect, PropertyStr, PropertyUint32, Role},
     scene::{Pimpl, SceneNodeWeak},
-    util::unixtime,
+    util::{spawn_thread, unixtime},
     ExecutorPtr,
 };
 
@@ -168,7 +168,8 @@ impl Video {
             let vid_data = self.vid_data.clone();
             let textures_pub = textures_pub.clone();
 
-            let handle = std::thread::spawn(move || {
+            let name = format!("video-load-{}", thread_idx);
+            let handle = spawn_thread(name, move || {
                 let now = std::time::Instant::now();
                 let mut frame_idx = thread_idx;
                 while frame_idx < vid_len {

+ 9 - 0
bin/app/src/util/mod.rs

@@ -31,6 +31,15 @@ pub fn unixtime() -> u64 {
     timest as u64
 }
 
+pub fn spawn_thread<F, T, S>(name: S, f: F) -> std::thread::JoinHandle<T>
+where
+    F: FnOnce() -> T + Send + 'static,
+    T: Send + 'static,
+    S: Into<String>,
+{
+    std::thread::Builder::new().name(name.into()).spawn(f).unwrap()
+}
+
 #[allow(dead_code)]
 pub fn ansi_texture(width: usize, height: usize, data: &Vec<u8>) -> String {
     let mut out = String::new();

+ 5 - 2
bin/app/src/util/rt.rs

@@ -21,6 +21,8 @@ use parking_lot::Mutex as SyncMutex;
 use smol::Task;
 use std::{sync::Arc, thread};
 
+use crate::util::spawn_thread;
+
 macro_rules! d { ($($arg:tt)*) => { debug!(target: "rt", $($arg)*); } }
 macro_rules! t { ($($arg:tt)*) => { trace!(target: "rt", $($arg)*); } }
 
@@ -57,11 +59,12 @@ impl AsyncRuntime {
     pub fn start_with_count(&self, n_threads: usize) {
         let mut exec_threadpool = Vec::with_capacity(n_threads);
         // N executor threads
-        for _ in 0..n_threads {
+        for i in 0..n_threads {
             let shutdown = self.shutdown.clone();
             let ex = self.ex.clone();
 
-            let handle = thread::spawn(move || {
+            let name = format!("{}-{}", self.name, i);
+            let handle = spawn_thread(name, move || {
                 let _ = smol::future::block_on(ex.run(shutdown.recv()));
             });
             exec_threadpool.push(handle);