|
1 | 1 | use jobserver_crate::Client;
|
2 | 2 | use lazy_static::lazy_static;
|
3 | 3 | use std::sync::atomic::{Ordering, AtomicUsize};
|
| 4 | +use rustc_serialize::json::as_json; |
4 | 5 |
|
5 | 6 | lazy_static! {
|
6 | 7 | // We can only call `from_env` once per process
|
@@ -30,17 +31,6 @@ lazy_static! {
|
30 | 31 | };
|
31 | 32 | }
|
32 | 33 |
|
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 |
| - |
44 | 34 | const EMPTY: usize = 0;
|
45 | 35 | const CARGO_REQUESTED: usize = 1;
|
46 | 36 | const MAKE_REQUESTED: usize = 2;
|
@@ -110,11 +100,34 @@ pub fn helper_thread<F>(mut cb: F) -> HelperThread
|
110 | 100 | }
|
111 | 101 | }
|
112 | 102 |
|
| 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 | + |
113 | 122 | pub fn acquire_thread() {
|
114 | 123 | notify_acquiring_token();
|
115 | 124 | GLOBAL_CLIENT.acquire_raw().ok();
|
116 | 125 | }
|
117 | 126 |
|
118 | 127 | 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 | + } |
120 | 133 | }
|
0 commit comments