You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// The token can either be a fresh token obtained from the jobserver or - if `token` is None - an implicit token for this process.
6
+
/// Both are valid values to put into queue.
7
+
token:Option<Acquired>,
8
+
pool:Sender<Option<Acquired>>,
9
+
should_return_to_queue:bool,
10
+
}
11
+
12
+
implDropforJobToken{
13
+
fndrop(&mutself){
14
+
ifself.should_return_to_queue{
15
+
let _ = self.pool.send(self.token.take());
16
+
}
17
+
}
18
+
}
19
+
20
+
implJobToken{
21
+
/// Ensure that this token is not put back into queue once it's dropped.
22
+
/// This also leads to releasing it sooner for other processes to use, which is a good thing to do once you know that
23
+
/// you're never going to request a token in this process again.
24
+
pub(crate)fnforget(&mutself){
25
+
self.should_return_to_queue = false;
26
+
}
27
+
}
28
+
29
+
/// A thin wrapper around jobserver's Client.
30
+
/// It would be perfectly fine to just use that, but we also want to reuse our own implicit token assigned for this build script.
31
+
/// This struct manages that and gives out tokens without exposing whether they're implicit tokens or tokens from jobserver.
32
+
/// Furthermore, instead of giving up job tokens, it keeps them around for reuse if we know we're going to request another token after freeing the current one.
// Since jobserver::Client::acquire can block, waiting
1387
1334
// must be done in parallel so that acquire won't block forever.
@@ -1394,6 +1341,10 @@ impl Build {
1394
1341
1395
1342
loop{
1396
1343
letmut has_made_progress = false;
1344
+
// If the other end of the pipe is already disconnected, then we're not gonna get any new jobs,
1345
+
// so it doesn't make sense to reuse the tokens; in fact, releasing them as soon as possible (once we know that the other end is disconnected) is beneficial.
1346
+
// Imagine that the last file built takes an hour to finish; in this scenario, by not releasing the tokens before other builds are done we'd effectively block other processes from
1347
+
// starting sooner - even though we only need one token, not however many we've acquired.
0 commit comments