about summary refs log tree commit diff
path: root/src/bootstrap/lib.rs
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2017-03-23 22:57:29 +0100
committerQuietMisdreavus <grey@quietmisdreavus.net>2017-05-16 16:25:57 -0500
commit1a7375b7e0fe41aa791ecf69dcceea7880302279 (patch)
treeeca7b4391da7793c7e53b2b291d07e2d13d6adfb /src/bootstrap/lib.rs
parent4d09a0eb5d201c831d19f3fe93fbe636eca7d97d (diff)
downloadrust-1a7375b7e0fe41aa791ecf69dcceea7880302279.tar.gz
rust-1a7375b7e0fe41aa791ecf69dcceea7880302279.zip
Add an option to run rustbuild on low priority
This is a resurrection of #40776, combining their Windows setup with an
additional setup on Unix to set the program group's niceness to +10
(low-but-not-lowest priority) when the `low_priority` option is on.
Diffstat (limited to 'src/bootstrap/lib.rs')
-rw-r--r--src/bootstrap/lib.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index ea0b521a2ce..a9f53cda7ed 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -76,6 +76,9 @@ extern crate num_cpus;
 extern crate rustc_serialize;
 extern crate toml;
 
+#[cfg(unix)]
+extern crate libc;
+
 use std::cmp;
 use std::collections::HashMap;
 use std::env;
@@ -108,9 +111,29 @@ pub mod util;
 #[cfg(windows)]
 mod job;
 
-#[cfg(not(windows))]
+#[cfg(unix)]
 mod job {
-    pub unsafe fn setup() {}
+    use libc;
+
+    //apparently glibc defines their own enum for this parameter, in a different type
+    #[cfg(not(any(target_env = "musl", target_env = "musleabi", target_env = "musleabihf",
+                  target_os = "emscripten", target_arch = "mips", target_arch = "mipsel")))]
+    const PRIO_PGRP: libc::c_uint = libc::PRIO_PGRP as libc::c_uint;
+    #[cfg(any(target_env = "musl", target_env = "musleabi", target_env = "musleabihf",
+              target_os = "emscripten", target_arch = "mips", target_arch = "mipsel"))]
+    const PRIO_PGRP: libc::c_int = libc::PRIO_PGRP;
+
+    pub unsafe fn setup(build: &mut ::Build) {
+        if build.config.low_priority {
+            libc::setpriority(PRIO_PGRP, 0, 10);
+        }
+    }
+}
+
+#[cfg(not(any(unix, windows)))]
+mod job {
+    pub unsafe fn setup(_build: &mut ::Build) {
+    }
 }
 
 pub use config::Config;
@@ -263,7 +286,7 @@ impl Build {
     /// Executes the entire build, as configured by the flags and configuration.
     pub fn build(&mut self) {
         unsafe {
-            job::setup();
+            job::setup(self);
         }
 
         if let Subcommand::Clean = self.flags.cmd {