diff --git a/src/rt/rust_chan.cpp b/src/rt/rust_chan.cpp index 44d45f693e73..e32c4214afc6 100644 --- a/src/rt/rust_chan.cpp +++ b/src/rt/rust_chan.cpp @@ -51,9 +51,9 @@ bool rust_chan::is_associated() { * Unlink this channel from its associated port. */ void rust_chan::disassociate() { + // Precondition: port->referent()->lock must be held A(kernel, is_associated(), "Channel must be associated with a port."); - scoped_lock with(port->referent()->lock); if (port->is_proxy() == false) { KLOG(kernel, task, "disassociating chan: 0x%" PRIxPTR " from port: 0x%" PRIxPTR, @@ -127,6 +127,7 @@ void rust_chan::destroy() { // Here is a good place to delete the port proxy we allocated // in upcall_clone_chan. rust_proxy *proxy = port->as_proxy(); + scoped_lock with(port->referent()->lock); disassociate(); delete proxy; } else { @@ -143,6 +144,7 @@ void rust_chan::destroy() { if (buffer.is_empty() == false) { return; } + scoped_lock with(port->referent()->lock); disassociate(); } } diff --git a/src/rt/rust_port.cpp b/src/rt/rust_port.cpp index 19592f4c8695..18acb38cc1d5 100644 --- a/src/rt/rust_port.cpp +++ b/src/rt/rust_port.cpp @@ -21,6 +21,7 @@ rust_port::~rust_port() { // Disassociate channels from this port. while (chans.is_empty() == false) { + scoped_lock with(referent()->lock); rust_chan *chan = chans.peek(); chan->disassociate();