mirror of
https://github.com/erg-lang/erg.git
synced 2025-07-20 03:25:18 +00:00
chore: add safe_yield
This commit is contained in:
parent
82792aca80
commit
bcd4e4deb7
2 changed files with 8 additions and 2 deletions
|
@ -50,3 +50,8 @@ where
|
||||||
.spawn(run)
|
.spawn(run)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn safe_yield() {
|
||||||
|
std::thread::yield_now();
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::thread::{current, JoinHandle, ThreadId};
|
||||||
use erg_common::dict::Dict;
|
use erg_common::dict::Dict;
|
||||||
use erg_common::pathutil::NormalizedPathBuf;
|
use erg_common::pathutil::NormalizedPathBuf;
|
||||||
use erg_common::shared::Shared;
|
use erg_common::shared::Shared;
|
||||||
|
use erg_common::spawn::safe_yield;
|
||||||
|
|
||||||
use super::SharedModuleGraph;
|
use super::SharedModuleGraph;
|
||||||
|
|
||||||
|
@ -155,7 +156,7 @@ impl SharedPromises {
|
||||||
.get(path)
|
.get(path)
|
||||||
.is_some_and(|p| !p.is_finished())
|
.is_some_and(|p| !p.is_finished())
|
||||||
{
|
{
|
||||||
std::thread::yield_now();
|
safe_yield();
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -167,7 +168,7 @@ impl SharedPromises {
|
||||||
|
|
||||||
pub fn join(&self, path: &Path) -> std::thread::Result<()> {
|
pub fn join(&self, path: &Path) -> std::thread::Result<()> {
|
||||||
while let Some(Promise::Joining) | None = self.promises.borrow().get(path) {
|
while let Some(Promise::Joining) | None = self.promises.borrow().get(path) {
|
||||||
std::thread::yield_now();
|
safe_yield();
|
||||||
}
|
}
|
||||||
let promise = self.promises.borrow_mut().get_mut(path).unwrap().take();
|
let promise = self.promises.borrow_mut().get_mut(path).unwrap().take();
|
||||||
self.join_checked(path, promise)
|
self.join_checked(path, promise)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue