Skip to content

Commit cf181ae

Browse files
committed
more interface cleanup
1 parent 3424d40 commit cf181ae

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

src/cargo/core/compiler/locking.rs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,15 @@ impl CompilationLock {
3030
}
3131
}
3232

33-
pub fn lock(self) -> Self {
34-
let unit_lock = self.unit.lock_exclusive();
33+
pub fn lock(&mut self) {
34+
self.unit.lock_exclusive();
3535

36-
let dependency_locks = self
37-
.dependency_units
38-
.into_iter()
39-
.map(|d| d.lock_shared())
40-
.collect::<Vec<_>>();
41-
42-
CompilationLock {
43-
unit: unit_lock,
44-
dependency_units: dependency_locks,
45-
}
36+
self.dependency_units
37+
.iter_mut()
38+
.for_each(|d| d.lock_shared());
4639
}
4740

48-
pub fn rmeta_produced(&self) {
41+
pub fn rmeta_produced(&mut self) {
4942
// Downgrade the lock on the unit we are building so that we can unblock other units to
5043
// compile. We do not need to downgrade our dependency locks since they should always be a
5144
// shared lock.
@@ -65,38 +58,34 @@ struct UnitLockGuard {
6558
}
6659

6760
impl UnitLock {
68-
pub fn lock_exclusive(self) -> UnitLock {
61+
pub fn lock_exclusive(&mut self) {
62+
assert!(self.gaurd.is_none());
63+
6964
let primary_lock = file_lock(&self.primary);
7065
primary_lock.lock().unwrap();
7166

7267
let secondary_lock = file_lock(&self.secondary);
7368
secondary_lock.lock().unwrap();
7469

75-
UnitLock {
76-
primary: self.primary,
77-
secondary: self.secondary,
78-
gaurd: Some(UnitLockGuard {
79-
primary: primary_lock,
80-
_secondary: Some(secondary_lock),
81-
}),
82-
}
70+
self.gaurd = Some(UnitLockGuard {
71+
primary: primary_lock,
72+
_secondary: Some(secondary_lock),
73+
});
8374
}
8475

85-
pub fn lock_shared(self) -> UnitLock {
76+
pub fn lock_shared(&mut self) {
77+
assert!(self.gaurd.is_none());
78+
8679
let primary_lock = file_lock(&self.primary);
8780
primary_lock.lock_shared().unwrap();
8881

89-
UnitLock {
90-
primary: self.primary,
91-
secondary: self.secondary,
92-
gaurd: Some(UnitLockGuard {
93-
primary: primary_lock,
94-
_secondary: None,
95-
}),
96-
}
82+
self.gaurd = Some(UnitLockGuard {
83+
primary: primary_lock,
84+
_secondary: None,
85+
});
9786
}
9887

99-
pub fn downgrade(&self) {
88+
pub fn downgrade(&mut self) {
10089
let gaurd = self.gaurd.as_ref().unwrap();
10190

10291
// TODO: Add debug asserts to verify the lock state?

src/cargo/core/compiler/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,17 @@ fn rustc(
354354
}
355355
let env_config = Arc::clone(build_runner.bcx.gctx.env_config()?);
356356

357-
let lock = if build_runner.bcx.gctx.cli_unstable().build_dir_new_layout {
357+
let mut lock = if build_runner.bcx.gctx.cli_unstable().build_dir_new_layout {
358358
Some(CompilationLock::new(build_runner, unit))
359359
} else {
360360
None
361361
};
362362

363363
return Ok(Work::new(move |state| {
364-
let mut lock = lock.map(|v| v.lock());
364+
if let Some(lock) = &mut lock {
365+
lock.lock();
366+
}
367+
// let mut lock = lock.map(|v| v.lock());
365368

366369
// Artifacts are in a different location than typical units,
367370
// hence we must assure the crate- and target-dependent

0 commit comments

Comments
 (0)