diff --git a/kernel/src/grant.rs b/kernel/src/grant.rs index d8522d9b5c..ecf2080d8d 100644 --- a/kernel/src/grant.rs +++ b/kernel/src/grant.rs @@ -619,6 +619,29 @@ impl<'a> GrantKernelData<'a> { ) } + /// Search the work queue for the first pending operation with the given + /// `subscribe_num` and if one exists remove it from the task queue. + /// + /// Returns the associated [`Task`] if one was found, otherwise returns + /// [`None`]. + pub fn remove_upcall(&self, subscribe_num: usize) -> Option { + self.process.remove_upcall(UpcallId { + subscribe_num, + driver_num: self.driver_num, + }) + } + + /// Remove all scheduled upcalls with the given `subscribe_num` from the + /// task queue. + /// + /// Returns the number of removed upcalls. + pub fn remove_pending_upcalls(&self, subscribe_num: usize) -> usize { + self.process.remove_pending_upcalls(UpcallId { + subscribe_num, + driver_num: self.driver_num, + }) + } + /// Returns a lifetime limited reference to the requested /// [`ReadOnlyProcessBuffer`]. /// diff --git a/kernel/src/kernel.rs b/kernel/src/kernel.rs index b408f0631a..1880d52f01 100644 --- a/kernel/src/kernel.rs +++ b/kernel/src/kernel.rs @@ -1017,7 +1017,7 @@ impl Kernel { // that there are no pending upcalls with the same // identifier but with the old function pointer, we // clear them now. - process.remove_pending_upcalls(upcall_id); + let _ =process.remove_pending_upcalls(upcall_id); } if config::CONFIG.trace_syscalls { diff --git a/kernel/src/process.rs b/kernel/src/process.rs index 3509fa7946..a4b461bff3 100644 --- a/kernel/src/process.rs +++ b/kernel/src/process.rs @@ -391,7 +391,9 @@ pub trait Process { /// Remove all scheduled upcalls with the given `upcall_id` from the task /// queue. - fn remove_pending_upcalls(&self, upcall_id: UpcallId); + /// + /// Returns the number of removed upcalls. + fn remove_pending_upcalls(&self, upcall_id: UpcallId) -> usize; /// Returns the current state the process is in. fn get_state(&self) -> State; diff --git a/kernel/src/process_standard.rs b/kernel/src/process_standard.rs index 5d4dc5592a..87ed46f9e9 100644 --- a/kernel/src/process_standard.rs +++ b/kernel/src/process_standard.rs @@ -552,8 +552,8 @@ impl Process for ProcessStandard<'_, || self.state.get() == State::Running } - fn remove_pending_upcalls(&self, upcall_id: UpcallId) { - self.tasks.map(|tasks| { + fn remove_pending_upcalls(&self, upcall_id: UpcallId) -> usize { + self.tasks.map_or(0, |tasks| { let count_before = tasks.len(); tasks.retain(|task| match task { // Remove only tasks that are function calls with an id equal @@ -564,8 +564,8 @@ impl Process for ProcessStandard<'_, }, _ => true, }); + let count_after = tasks.len(); if config::CONFIG.trace_syscalls { - let count_after = tasks.len(); debug!( "[{:?}] remove_pending_upcalls[{:#x}:{}] = {} upcall(s) removed", self.processid(), @@ -574,7 +574,8 @@ impl Process for ProcessStandard<'_, count_before - count_after, ); } - }); + count_after - count_before + }) } fn is_running(&self) -> bool {