Skip to content

Commit 7578d0a

Browse files
committed
Remove total
1 parent 2dfc7cd commit 7578d0a

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

compiler/rustc_data_structures/src/jobserver.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ pub fn client() -> Client {
7373
}
7474

7575
struct ProxyData {
76-
/// The number of tokens assigned to this process.
77-
total: u16,
78-
7976
/// The number of tokens assigned to threads.
77+
/// If this is 0, a single token is still assigned to this process, but is unused.
8078
used: u16,
8179

8280
/// The number of threads requesting a token
@@ -98,7 +96,7 @@ impl Proxy {
9896
pub fn new() -> Arc<Self> {
9997
let proxy = Arc::new(Proxy {
10098
client: client(),
101-
data: Mutex::new(ProxyData { total: 1, used: 1, pending: 0 }),
99+
data: Mutex::new(ProxyData { used: 1, pending: 0 }),
102100
wake_pending: Condvar::new(),
103101
helper: OnceLock::new(),
104102
});
@@ -112,7 +110,7 @@ impl Proxy {
112110
if data.pending > 0 {
113111
// Give the token to a waiting thread
114112
token.drop_without_releasing();
115-
data.total += 1;
113+
assert!(data.used > 0);
116114
data.used += 1;
117115
data.pending -= 1;
118116
proxy_.wake_pending.notify_one();
@@ -131,10 +129,9 @@ impl Proxy {
131129
pub fn acquire_thread(&self) {
132130
let mut data = self.data.lock();
133131

134-
if data.total > data.used {
132+
if data.used == 0 {
135133
// There was a free token around. This can
136134
// happen when all threads release their token.
137-
assert_eq!(data.total, 1);
138135
assert_eq!(data.pending, 0);
139136
data.used += 1;
140137
} else {
@@ -158,8 +155,7 @@ impl Proxy {
158155
data.used -= 1;
159156

160157
// Release the token unless it's the last one in the process
161-
if data.total > 1 {
162-
data.total -= 1;
158+
if data.used > 0 {
163159
drop(data);
164160
self.client.release_raw().ok();
165161
}

0 commit comments

Comments
 (0)