Browse Source

Update to use std threads

Yay! Deleting code is nice.
pull/46/head
AzureMarker 3 years ago
parent
commit
a6b102f156
No known key found for this signature in database
GPG Key ID: 47A133F3BF9D03D3
  1. 2
      ctru-rs/examples/futures-basic.rs
  2. 2
      ctru-rs/examples/futures-tokio.rs
  3. 7
      ctru-rs/examples/thread-basic.rs
  4. 2
      ctru-rs/examples/thread-locals.rs
  5. 4
      ctru-rs/src/lib.rs
  6. 1039
      ctru-rs/src/thread.rs

2
ctru-rs/examples/futures-basic.rs

@ -26,7 +26,7 @@ fn main() {
let (exit_sender, mut exit_receiver) = futures::channel::oneshot::channel(); let (exit_sender, mut exit_receiver) = futures::channel::oneshot::channel();
let (mut timer_sender, mut timer_receiver) = futures::channel::mpsc::channel(0); let (mut timer_sender, mut timer_receiver) = futures::channel::mpsc::channel(0);
let executor_thread = ctru::thread::Builder::new() let executor_thread = std::thread::Builder::new()
.affinity(1) .affinity(1)
.spawn(move || { .spawn(move || {
let mut executor = futures::executor::LocalPool::new(); let mut executor = futures::executor::LocalPool::new();

2
ctru-rs/examples/futures-tokio.rs

@ -25,7 +25,7 @@ fn main() {
.build() .build()
.expect("Couldn't build runtime"); .expect("Couldn't build runtime");
let runtime_thread = ctru::thread::Builder::new() let runtime_thread = std::thread::Builder::new()
// Run on the system core // Run on the system core
.affinity(1) .affinity(1)
// Use a bigger stack size. Default is 0x1000 but we'd easily overflow that. // Use a bigger stack size. Default is 0x1000 but we'd easily overflow that.

7
ctru-rs/examples/thread-basic.rs

@ -2,7 +2,6 @@ use ctru::console::Console;
use ctru::gfx::Gfx; use ctru::gfx::Gfx;
use ctru::services::apt::Apt; use ctru::services::apt::Apt;
use ctru::services::hid::{Hid, KeyPad}; use ctru::services::hid::{Hid, KeyPad};
use ctru::thread;
use std::time::Duration; use std::time::Duration;
@ -14,11 +13,11 @@ fn main() {
let gfx = Gfx::default(); let gfx = Gfx::default();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());
let prio = thread::current().priority(); let prio = ctru::thread::priority();
println!("Main thread prio: {}\n", prio); println!("Main thread prio: {}\n", prio);
for ix in 0..3 { for ix in 0..3 {
thread::Builder::new() std::thread::Builder::new()
.priority(prio - 1) .priority(prio - 1)
.spawn(move || { .spawn(move || {
let sleep_duration: u64 = 1000 + ix * 250; let sleep_duration: u64 = 1000 + ix * 250;
@ -26,7 +25,7 @@ fn main() {
loop { loop {
println!("Thread{ix} says {i}"); println!("Thread{ix} says {i}");
i += 1; i += 1;
thread::sleep(Duration::from_millis(sleep_duration)); std::thread::sleep(Duration::from_millis(sleep_duration));
} }
}) })
.unwrap(); .unwrap();

2
ctru-rs/examples/thread-locals.rs

@ -28,7 +28,7 @@ fn main() {
println!("Value on main thread after mutation: {}", local.borrow()); println!("Value on main thread after mutation: {}", local.borrow());
}); });
ctru::thread::Builder::new() std::thread::Builder::new()
.affinity(1) .affinity(1)
.spawn(move || { .spawn(move || {
MY_LOCAL.with(|local| { MY_LOCAL.with(|local| {

4
ctru-rs/src/lib.rs

@ -14,7 +14,7 @@ pub fn init() {
use std::panic::PanicInfo; use std::panic::PanicInfo;
let main_thread = thread::current().id(); let main_thread = std::thread::current().id();
// Panic Hook setup // Panic Hook setup
let default_hook = std::panic::take_hook(); let default_hook = std::panic::take_hook();
@ -22,7 +22,7 @@ pub fn init() {
default_hook(info); default_hook(info);
// Only for panics in the main thread // Only for panics in the main thread
if main_thread == thread::current().id() && console::Console::exists() { if main_thread == std::thread::current().id() && console::Console::exists() {
println!("\nPress SELECT to exit the software"); println!("\nPress SELECT to exit the software");
let hid = services::hid::Hid::init().unwrap(); let hid = services::hid::Hid::init().unwrap();

1039
ctru-rs/src/thread.rs

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save