mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Prevent deadlock
This commit is contained in:
parent
cc9a574b2e
commit
4ca1f661d5
1 changed files with 1 additions and 17 deletions
|
@ -1,8 +1,3 @@
|
|||
use std::{
|
||||
hint,
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
|
||||
use hyper::{Body, Method, Request};
|
||||
use serde::Deserialize;
|
||||
|
||||
|
@ -40,7 +35,6 @@ impl Default for ApResolveData {
|
|||
component! {
|
||||
ApResolver : ApResolverInner {
|
||||
data: AccessPoints = AccessPoints::default(),
|
||||
in_progress: AtomicBool = AtomicBool::new(false),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,16 +105,6 @@ impl ApResolver {
|
|||
}
|
||||
|
||||
pub async fn resolve(&self, endpoint: &str) -> Result<SocketAddress, Error> {
|
||||
// Use a spinlock to make this function atomic. Otherwise, various race conditions may
|
||||
// occur, e.g. when the session is created, multiple components are launched almost in
|
||||
// parallel and they will all call this function, while resolving is still in progress.
|
||||
self.lock(|inner| {
|
||||
while inner.in_progress.load(Ordering::Acquire) {
|
||||
hint::spin_loop();
|
||||
}
|
||||
inner.in_progress.store(true, Ordering::Release);
|
||||
});
|
||||
|
||||
if self.is_empty() {
|
||||
self.apresolve().await;
|
||||
}
|
||||
|
@ -140,7 +124,7 @@ impl ApResolver {
|
|||
)))
|
||||
}
|
||||
};
|
||||
inner.in_progress.store(false, Ordering::Release);
|
||||
|
||||
Ok(access_point)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue