From daa6086bc98d46218cf3728b0af21e31f9db19ef Mon Sep 17 00:00:00 2001 From: Taylor Whatley <32211852+1whatleytay@users.noreply.github.com> Date: Wed, 20 Mar 2024 15:54:33 -0400 Subject: [PATCH] Spawn task on another thread --- src-backend/Cargo.lock | 22 +++---- src-backend/Cargo.toml | 2 +- src-backend/src/execution.rs | 13 ++--- src-backend/src/syscall.rs | 13 +++-- src-tauri/Cargo.lock | 110 ++++++++++++++++++----------------- src-tauri/Cargo.toml | 2 +- src-tauri/src/state.rs | 4 +- 7 files changed, 85 insertions(+), 81 deletions(-) diff --git a/src-backend/Cargo.lock b/src-backend/Cargo.lock index 0ba9b05..55eff92 100644 --- a/src-backend/Cargo.lock +++ b/src-backend/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "async-trait" -version = "0.1.77" +version = "0.1.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" +checksum = "461abc97219de0eaaf81fe3ef974a540158f3d079c2ab200f891f1a2ef201e85" dependencies = [ "proc-macro2", "quote", @@ -57,9 +57,9 @@ checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "byteorder" @@ -75,9 +75,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cc" -version = "1.0.86" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9fa1897e4325be0d68d48df6aa1a71ac2ed4d27723887e7754192705350730" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" [[package]] name = "cfg-if" @@ -244,9 +244,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -340,9 +340,9 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "syn" -version = "2.0.50" +version = "2.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" +checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" dependencies = [ "proc-macro2", "quote", @@ -352,7 +352,7 @@ dependencies = [ [[package]] name = "titan" version = "0.1.0" -source = "git+https://github.com/1whatleytay/titan.git?branch=main#aaeb8af73378f6d46a4019dee77ba4d717de4787" +source = "git+https://github.com/1whatleytay/titan.git?branch=lock-test#ed451c0a3559e859f0cc059b84188ee2b3c9cc53" dependencies = [ "bitflags", "byteorder", diff --git a/src-backend/Cargo.toml b/src-backend/Cargo.toml index 6de00f2..db9739d 100644 --- a/src-backend/Cargo.toml +++ b/src-backend/Cargo.toml @@ -20,4 +20,4 @@ rand_chacha = "0.3.1" tokio-util = "0.7.10" async-trait = "0.1.77" -titan = { git = "https://github.com/1whatleytay/titan.git", branch = "main" } +titan = { git = "https://github.com/1whatleytay/titan.git", branch = "lock-test" } diff --git a/src-backend/src/execution.rs b/src-backend/src/execution.rs index 3cdbc9a..d05e93a 100644 --- a/src-backend/src/execution.rs +++ b/src-backend/src/execution.rs @@ -2,7 +2,6 @@ use crate::display::{FlushDisplayBody, read_display}; use crate::syscall::{SyscallDelegate, SyscallResult}; use serde::Serialize; use std::collections::HashSet; -use async_trait::async_trait; use titan::cpu::error::Error::{CpuTrap, MemoryAlign, MemoryUnmapped}; use titan::cpu::{Memory, State}; use titan::cpu::memory::section::{ListenResponder, SectionMemory}; @@ -149,9 +148,8 @@ pub trait ExecutionRewindable { pub trait RewindableDevice: ExecutionDevice + ExecutionRewindable { } -#[async_trait] pub trait ExecutionDevice: Send + Sync { - async fn resume( + fn resume( &self, count: Option, breakpoints: Option>, @@ -173,9 +171,8 @@ pub trait ExecutionDevice: Send + Sync { fn post_input(&self, text: String); } -#[async_trait] impl + Send> ExecutionDevice for ExecutionState { - async fn resume( + fn resume( &self, count: Option, breakpoints: Option>, @@ -202,16 +199,16 @@ impl + Send> ExecutionDevice for Executi if let Some(count) = count { // Taylor: Why did I split the last iteration out? for _ in 0..count - 1 { - delegate.cycle(&debugger).await; + delegate.cycle(&debugger); } if count > 0 { - delegate.cycle(&debugger).await + delegate.cycle(&debugger) } else { return Err(()); } } else { - delegate.run(&debugger).await + delegate.run(&debugger) } }; diff --git a/src-backend/src/syscall.rs b/src-backend/src/syscall.rs index 4f278d0..dfe3b4c 100644 --- a/src-backend/src/syscall.rs +++ b/src-backend/src/syscall.rs @@ -23,6 +23,7 @@ use titan::execution::Executor; use titan::execution::trackers::Tracker; use tokio::select; use tokio::sync::Notify; +use tokio::runtime::Handle; use tokio_util::sync::CancellationToken; pub struct MidiRequest { @@ -734,7 +735,7 @@ impl SyscallDelegate { } } - async fn handle_frame>( + fn handle_frame>( &self, debugger: &Executor, frame: DebugFrame, @@ -743,7 +744,7 @@ impl SyscallDelegate { Invalid(CpuSyscall) => { // $v0 let code = debugger.with_state(|s| s.registers.line[V0_REG]); - let result = self.dispatch(debugger, code).await; + let result = Handle::current().block_on(self.dispatch(debugger, code)); ( match result { @@ -761,12 +762,12 @@ impl SyscallDelegate { } } - pub async fn run>( + pub fn run>( &self, debugger: &Executor ) -> (DebugFrame, Option) { loop { let frame = debugger.run(); - let (frame, result) = self.handle_frame(debugger, frame).await; + let (frame, result) = self.handle_frame(debugger, frame); if let Some(frame) = frame { return (frame, result); @@ -781,14 +782,14 @@ impl SyscallDelegate { } } - pub async fn cycle + Send>( + pub fn cycle + Send>( &self, debugger: &Executor, ) -> (DebugFrame, Option) { let frame = debugger.cycle(true); let (frame, result) = if let Some(frame) = frame { - self.handle_frame(debugger, frame).await + self.handle_frame(debugger, frame) } else { (None, None) }; diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0e0c2d4..bb145ce 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -164,7 +164,7 @@ dependencies = [ "futures-lite 2.3.0", "parking", "polling 3.5.0", - "rustix 0.38.31", + "rustix 0.38.32", "slab", "tracing", "windows-sys 0.52.0", @@ -203,7 +203,7 @@ dependencies = [ "cfg-if", "event-listener 3.1.0", "futures-lite 1.13.0", - "rustix 0.38.31", + "rustix 0.38.32", "windows-sys 0.48.0", ] @@ -230,7 +230,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 0.38.31", + "rustix 0.38.32", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -274,7 +274,7 @@ dependencies = [ "glib-sys", "gobject-sys", "libc", - "system-deps 6.2.1", + "system-deps 6.2.2", ] [[package]] @@ -324,9 +324,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "block" @@ -438,7 +438,7 @@ checksum = "3c55d429bef56ac9172d25fecb85dc8068307d17acd74b377866b7a1ef25d3c8" dependencies = [ "glib-sys", "libc", - "system-deps 6.2.1", + "system-deps 6.2.2", ] [[package]] @@ -902,7 +902,7 @@ dependencies = [ "cc", "memchr", "rustc_version", - "toml 0.8.11", + "toml 0.8.12", "vswhom", "winreg 0.52.0", ] @@ -1327,7 +1327,7 @@ dependencies = [ "glib-sys", "gobject-sys", "libc", - "system-deps 6.2.1", + "system-deps 6.2.2", ] [[package]] @@ -1344,7 +1344,7 @@ dependencies = [ "libc", "pango-sys", "pkg-config", - "system-deps 6.2.1", + "system-deps 6.2.2", ] [[package]] @@ -1358,7 +1358,7 @@ dependencies = [ "gobject-sys", "libc", "pkg-config", - "system-deps 6.2.1", + "system-deps 6.2.2", ] [[package]] @@ -1370,7 +1370,7 @@ dependencies = [ "gdk-sys", "glib-sys", "libc", - "system-deps 6.2.1", + "system-deps 6.2.2", "x11", ] @@ -1461,7 +1461,7 @@ dependencies = [ "glib-sys", "gobject-sys", "libc", - "system-deps 6.2.1", + "system-deps 6.2.2", "winapi", ] @@ -1507,7 +1507,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef4b192f8e65e9cf76cbf4ea71fa8e3be4a0e18ffe3d68b8da6836974cc5bad4" dependencies = [ "libc", - "system-deps 6.2.1", + "system-deps 6.2.2", ] [[package]] @@ -1537,7 +1537,7 @@ checksum = "0d57ce44246becd17153bd035ab4d32cfee096a657fc01f2231c9278378d1e0a" dependencies = [ "glib-sys", "libc", - "system-deps 6.2.1", + "system-deps 6.2.2", ] [[package]] @@ -1578,7 +1578,7 @@ dependencies = [ "gobject-sys", "libc", "pango-sys", - "system-deps 6.2.1", + "system-deps 6.2.2", ] [[package]] @@ -1641,6 +1641,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -2052,7 +2058,7 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libc", "redox_syscall", ] @@ -2294,7 +2300,7 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "cfg-if", "cfg_aliases", "libc", @@ -2322,7 +2328,7 @@ version = "6.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "crossbeam-channel", "filetime", "fsevent-sys", @@ -2551,7 +2557,7 @@ version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "cfg-if", "foreign-types 0.3.2", "libc", @@ -2648,7 +2654,7 @@ dependencies = [ "glib-sys", "gobject-sys", "libc", - "system-deps 6.2.1", + "system-deps 6.2.2", ] [[package]] @@ -2917,7 +2923,7 @@ dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite", - "rustix 0.38.31", + "rustix 0.38.32", "tracing", "windows-sys 0.52.0", ] @@ -3169,9 +3175,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.26" +version = "0.11.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78bf93c4af7a8bb7d879d51cebe797356ff10ae8516ace542b5182d9dcac10b2" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" dependencies = [ "base64 0.21.7", "bytes", @@ -3264,11 +3270,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.31" +version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys 0.4.13", @@ -3801,15 +3807,15 @@ dependencies = [ [[package]] name = "system-deps" -version = "6.2.1" +version = "6.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8e9199467bcbc77c6a13cc6e32a6af21721ab8c96aa0261856c4fda5a4433f0" +checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" dependencies = [ "cfg-expr 0.15.7", - "heck 0.4.1", + "heck 0.5.0", "pkg-config", - "toml 0.8.11", - "version-compare 0.1.1", + "toml 0.8.12", + "version-compare 0.2.0", ] [[package]] @@ -4105,7 +4111,7 @@ checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand 2.0.1", - "rustix 0.38.31", + "rustix 0.38.32", "windows-sys 0.52.0", ] @@ -4216,9 +4222,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "titan" version = "0.1.0" -source = "git+https://github.com/1whatleytay/titan.git?branch=main#aaeb8af73378f6d46a4019dee77ba4d717de4787" +source = "git+https://github.com/1whatleytay/titan.git?branch=lock-test#ed451c0a3559e859f0cc059b84188ee2b3c9cc53" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "byteorder", "num", "num-derive", @@ -4302,14 +4308,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af06656561d28735e9c1cd63dfd57132c8155426aa6af24f36a00a351f88c48e" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.7", + "toml_edit 0.22.8", ] [[package]] @@ -4336,9 +4342,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.7" +version = "0.22.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18769cd1cec395d70860ceb4d932812a0b4d06b1a4bb336745a4d21b9496e992" +checksum = "c12219811e0c1ba077867254e5ad62ee2c9c190b0d957110750ac0cda1ae96cd" dependencies = [ "indexmap 2.2.5", "serde", @@ -4513,9 +4519,9 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" [[package]] name = "uuid" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" +checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" dependencies = [ "getrandom 0.2.12", ] @@ -4540,9 +4546,9 @@ checksum = "1c18c859eead79d8b95d09e4678566e8d70105c4e7b251f707a03df32442661b" [[package]] name = "version-compare" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29" +checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" [[package]] name = "version_check" @@ -4694,7 +4700,7 @@ checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40" dependencies = [ "cc", "downcast-rs", - "rustix 0.38.31", + "rustix 0.38.32", "scoped-tls", "smallvec", "wayland-sys", @@ -4706,8 +4712,8 @@ version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f" dependencies = [ - "bitflags 2.4.2", - "rustix 0.38.31", + "bitflags 2.5.0", + "rustix 0.38.32", "wayland-backend", "wayland-scanner", ] @@ -4718,7 +4724,7 @@ version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "wayland-backend", "wayland-client", "wayland-scanner", @@ -4730,7 +4736,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "wayland-backend", "wayland-client", "wayland-protocols", @@ -4813,7 +4819,7 @@ dependencies = [ "pango-sys", "pkg-config", "soup2-sys", - "system-deps 6.2.1", + "system-deps 6.2.2", ] [[package]] @@ -5393,7 +5399,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8f25ead8c7e4cba123243a6367da5d3990e0d3affa708ea19dce96356bd9f1a" dependencies = [ "gethostname", - "rustix 0.38.31", + "rustix 0.38.32", "x11rb-protocol", ] @@ -5411,7 +5417,7 @@ checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f" dependencies = [ "libc", "linux-raw-sys 0.4.13", - "rustix 0.38.31", + "rustix 0.38.32", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index a57501b..249e0c2 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -26,7 +26,7 @@ notify = "6.1.1" base64 = "0.21.5" saturn_backend = { path = "../src-backend" } -titan = { git = "https://github.com/1whatleytay/titan.git", branch = "main" } +titan = { git = "https://github.com/1whatleytay/titan.git", branch = "lock-test" } [features] default = [ "custom-protocol" ] diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs index 5f49219..e4590bd 100644 --- a/src-tauri/src/state.rs +++ b/src-tauri/src/state.rs @@ -27,8 +27,8 @@ pub async fn resume( let display = display.inner().clone(); - tokio::spawn(async move { - context.resume(count, breakpoints, Some(display)).await + tokio::task::spawn_blocking(move || { + context.resume(count, breakpoints, Some(display)) }).await.map_err(|_| ())? }