From ae6ca6fb231321770a4bd47769d23d120dc33acc Mon Sep 17 00:00:00 2001 From: James Onnen Date: Sun, 17 Dec 2017 14:20:24 -0600 Subject: [PATCH 1/3] Fix #21: High CPU usage in a small project --- src/bin.rs | 5 ++++- src/vfs_watch.rs | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index 4c42a4cf..b0ff3a68 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -22,6 +22,7 @@ pub mod vfs_watch; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; use std::thread; +use std::time::Duration; use core::Config; use pathext::canonicalish; @@ -193,7 +194,9 @@ fn main() { println!("Server listening on port {}", port); - loop {} + loop { + thread::sleep(Duration::from_secs(1)); + } }, ("pack", _) => { eprintln!("'rojo pack' is not yet implemented!"); diff --git a/src/vfs_watch.rs b/src/vfs_watch.rs index 697b9ff6..f28e200f 100644 --- a/src/vfs_watch.rs +++ b/src/vfs_watch.rs @@ -92,6 +92,8 @@ impl VfsWatcher { } } - loop {} + loop { + thread::sleep(Duration::from_secs(1)); + } } } From 199ebda68904f55d684eaea6aaaee6130ca16196 Mon Sep 17 00:00:00 2001 From: James Onnen Date: Sun, 17 Dec 2017 14:34:31 -0600 Subject: [PATCH 2/3] Use ::park() instead of ::sleep() --- src/bin.rs | 2 +- src/vfs_watch.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index b0ff3a68..9422c62c 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -195,7 +195,7 @@ fn main() { println!("Server listening on port {}", port); loop { - thread::sleep(Duration::from_secs(1)); + thread::park(); } }, ("pack", _) => { diff --git a/src/vfs_watch.rs b/src/vfs_watch.rs index f28e200f..872ba683 100644 --- a/src/vfs_watch.rs +++ b/src/vfs_watch.rs @@ -93,7 +93,7 @@ impl VfsWatcher { } loop { - thread::sleep(Duration::from_secs(1)); + thread::park(); } } } From 5a20646c570be931f114789330ae28bc813b9d2e Mon Sep 17 00:00:00 2001 From: James Onnen Date: Sun, 17 Dec 2017 23:40:32 -0600 Subject: [PATCH 3/3] Address code review, remove unnecessary import --- src/bin.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin.rs b/src/bin.rs index 9422c62c..b04500a9 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -22,7 +22,6 @@ pub mod vfs_watch; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; use std::thread; -use std::time::Duration; use core::Config; use pathext::canonicalish;