mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Avoid locking main thread
This commit is contained in:
parent
be9bb136eb
commit
4e096d5443
@ -57,7 +57,7 @@ impl WorkerLoop {
|
||||
}
|
||||
loaded_coords.insert(coords);
|
||||
info!("new tile request: {:?}", &coords);
|
||||
self.requests.push(coords);
|
||||
while !self.requests.try_push(coords) {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,13 +142,23 @@ impl<T: Send> WorkQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn push(&self, work: T) -> usize {
|
||||
fn push(&self, work: T) -> bool {
|
||||
if let Ok(mut queue) = self.inner.lock() {
|
||||
queue.push_back(work);
|
||||
self.cvar.notify_all();
|
||||
queue.len()
|
||||
true
|
||||
} else {
|
||||
panic!("locking failed");
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn try_push(&self, work: T) -> bool {
|
||||
if let Ok(mut queue) = self.inner.try_lock() {
|
||||
queue.push_back(work);
|
||||
self.cvar.notify_all();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user