event: reduce lock scope to allow re-locking in event handler

The following "Port execution" commit will use RefCell for the wait handle
store.  If we hold a borrow while we are running an event (which may run
script code) there will be a borrowing conflict. Avoid this by returning
the borrow earlier.
This commit is contained in:
Johannes Altmanninger
2023-09-16 21:51:05 +02:00
parent 575c271461
commit d15e475440

View File

@@ -356,16 +356,14 @@ pub fn function(
for ed in &opts.events {
match *ed {
EventDescription::ProcessExit { pid } if pid != event::ANY_PID => {
if let Some(status) = parser
.get_wait_handles()
.get_by_pid(pid)
.and_then(|wh| wh.status())
{
let wh = parser.get_wait_handles().get_by_pid(pid);
if let Some(status) = wh.and_then(|wh| wh.status()) {
event::fire(parser, event::Event::process_exit(pid, status));
}
}
EventDescription::JobExit { pid, .. } if pid != event::ANY_PID => {
if let Some(wh) = parser.get_wait_handles().get_by_pid(pid) {
let wh = parser.get_wait_handles().get_by_pid(pid);
if let Some(wh) = wh {
if wh.is_completed() {
event::fire(parser, event::Event::job_exit(pid, wh.internal_job_id));
}