Avoid locking main thread

This commit is contained in:
Maximilian Ammann 2022-01-23 14:06:58 +01:00
parent be9bb136eb
commit 4e096d5443

View File

@ -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
}
}
}