Fix deadlock

This commit is contained in:
Jeremy Soller 2016-09-20 09:21:54 -06:00
parent 791dbfa7ad
commit d329f7c7d2
4 changed files with 37 additions and 29 deletions

View file

@ -48,8 +48,11 @@ impl UserInner {
self.todo.lock().push_back(packet);
loop {
if let Some(a) = self.done.lock().remove(&id) {
return convert_to_result(a);
{
let mut done = self.done.lock();
if let Some(a) = done.remove(&id) {
return convert_to_result(a);
}
}
unsafe { context::switch(); }
@ -89,7 +92,6 @@ impl UserInner {
while i < len {
let packet = unsafe { *(buf.as_ptr() as *const Packet).offset(i as isize) };
self.done.lock().insert(packet.id, packet.a);
i += 1;
}