Threading performance optimizations
This commit is contained in:
@@ -21,6 +21,6 @@
|
||||
extern crate gcc;
|
||||
|
||||
fn main() {
|
||||
gcc::compile_library("libtinykeccak.a", &["src/tinykeccak.c"]);
|
||||
gcc::Config::new().file("src/tinykeccak.c").flag("-O3").compile("libtinykeccak.a");
|
||||
}
|
||||
|
||||
|
||||
@@ -143,6 +143,7 @@ pub mod network;
|
||||
pub mod log;
|
||||
pub mod panics;
|
||||
pub mod keys;
|
||||
mod thread;
|
||||
|
||||
pub use common::*;
|
||||
pub use misc::*;
|
||||
@@ -163,4 +164,5 @@ pub use semantic_version::*;
|
||||
pub use network::*;
|
||||
pub use io::*;
|
||||
pub use log::*;
|
||||
pub use thread::*;
|
||||
|
||||
|
||||
43
util/src/thread.rs
Normal file
43
util/src/thread.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Thread management helpers
|
||||
|
||||
use libc::{c_int, pthread_self, pthread_t};
|
||||
|
||||
#[repr(C)]
|
||||
struct sched_param {
|
||||
priority: c_int,
|
||||
padding: c_int,
|
||||
}
|
||||
|
||||
extern {
|
||||
fn setpriority(which: c_int, who: c_int, prio: c_int) -> c_int;
|
||||
fn pthread_setschedparam(thread: pthread_t, policy: c_int, param: *const sched_param) -> c_int;
|
||||
}
|
||||
const PRIO_DARWIN_THREAD: c_int = 3;
|
||||
const PRIO_DARWIN_BG: c_int = 0x1000;
|
||||
const SCHED_RR: c_int = 2;
|
||||
|
||||
/// Lower thread priority and put it into background mode
|
||||
#[cfg(target_os="macos")]
|
||||
pub fn lower_thread_priority() {
|
||||
let sp = sched_param { priority: 0, padding: 0 };
|
||||
if unsafe { pthread_setschedparam(pthread_self(), SCHED_RR, &sp) } == -1 {
|
||||
trace!("Could not decrease thread piority");
|
||||
}
|
||||
//unsafe { setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG); }
|
||||
}
|
||||
Reference in New Issue
Block a user