Skip to content

Commit 3900705

Browse files
Implement jobserver event communication
1 parent 71fceab commit 3900705

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3649,6 +3649,7 @@ version = "0.0.0"
36493649
dependencies = [
36503650
"jobserver",
36513651
"lazy_static 1.3.0",
3652+
"serialize",
36523653
]
36533654

36543655
[[package]]

src/librustc_jobserver/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ doctest = false
1212
[dependencies]
1313
jobserver_crate = { version = "0.1.13", package = "jobserver" }
1414
lazy_static = "1"
15+
rustc_serialize = { path = "../libserialize", package = "serialize" }

src/librustc_jobserver/lib.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use jobserver_crate::Client;
22
use lazy_static::lazy_static;
33
use std::sync::atomic::{Ordering, AtomicUsize};
4+
use rustc_serialize::json::as_json;
45

56
lazy_static! {
67
// We can only call `from_env` once per process
@@ -30,17 +31,6 @@ lazy_static! {
3031
};
3132
}
3233

33-
// Unlike releasing tokens, there's not really a "one size fits all" approach, as we have two
34-
// primary ways of acquiring a token: via the helper thread, and via the acquire_thread function.
35-
//
36-
// That makes this function necessary unlike in the release case where everything is piped through
37-
// `release_thread`.
38-
fn notify_acquiring_token() {
39-
if should_notify() {
40-
// FIXME: tell Cargo of our interest
41-
}
42-
}
43-
4434
const EMPTY: usize = 0;
4535
const CARGO_REQUESTED: usize = 1;
4636
const MAKE_REQUESTED: usize = 2;
@@ -110,11 +100,34 @@ pub fn helper_thread<F>(mut cb: F) -> HelperThread
110100
}
111101
}
112102

103+
#[derive(RustcEncodable)]
104+
enum Event {
105+
WillAcquire,
106+
Release,
107+
}
108+
109+
#[derive(RustcEncodable)]
110+
struct JobserverNotification {
111+
jobserver_event: Event,
112+
}
113+
114+
// Unlike releasing tokens, there's not really a "one size fits all" approach, as we have two
115+
// primary ways of acquiring a token: via the helper thread, and via the acquire_thread function.
116+
fn notify_acquiring_token() {
117+
if should_notify() {
118+
eprintln!("{}", as_json(&JobserverNotification { jobserver_event: Event::WillAcquire }));
119+
}
120+
}
121+
113122
pub fn acquire_thread() {
114123
notify_acquiring_token();
115124
GLOBAL_CLIENT.acquire_raw().ok();
116125
}
117126

118127
pub fn release_thread() {
119-
GLOBAL_CLIENT.release_raw().ok();
128+
if should_notify() {
129+
eprintln!("{}", as_json(&JobserverNotification { jobserver_event: Event::Release }));
130+
} else {
131+
GLOBAL_CLIENT.release_raw().ok();
132+
}
120133
}

0 commit comments

Comments
 (0)