From c32706e4aff8d53be83994cdf0ed5d67bd64c626 Mon Sep 17 00:00:00 2001 From: Michael Preisach Date: Wed, 1 May 2019 00:14:23 +0200 Subject: [PATCH] adding process priority --- Cargo.lock | 10 ++++++++++ Cargo.toml | 3 ++- src/main.rs | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 8278a75..7570a1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,6 +21,7 @@ version = "0.1.0" dependencies = [ "gpio 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "rppal 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", + "thread-priority 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -32,8 +33,17 @@ dependencies = [ "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "thread-priority" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum gpio 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe6783270536547ac473c9d2ae5a7e0e715ea43f29004ced47fbd1c1372d2c7" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" "checksum rppal 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "47fa3e09d34f2992f47f3d4315f8ee8cfffc1fe1912d4d08258b66cc18dc3b00" +"checksum thread-priority 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e655c097854cf47b40825a61c2edf7b96119ce9e02a9ff09e8b609b67f3c05e2" diff --git a/Cargo.toml b/Cargo.toml index 11d9bae..7a263ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ edition = "2018" [dependencies] rppal = "0.11.1" -gpio = "0.4.1" \ No newline at end of file +gpio = "0.4.1" +thread-priority = "0.1.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 15f4f39..0296fe7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +extern crate thread_priority; +use thread_priority::*; use std::net::{TcpStream, TcpListener}; use std::io::prelude::*; use std::io::{BufReader, Result}; @@ -61,6 +63,11 @@ fn handle_connection(stream: TcpStream, prot: &mut protocol::Protocol) -> Result } fn main() -> Result<()> { + let thread_id = thread_native_id(); + assert!(set_thread_priority(thread_id, + ThreadPriority::Max, + ThreadSchedulePolicy::Realtime(RealtimeThreadSchedulePolicy::RoundRobin)).is_ok()); + let address = "0.0.0.0:8000"; println!("Initialize network"); let listener = TcpListener::bind(address).expect("could not start server");