mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 03:13:23 +00:00
Check the length of timers before delete
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
c38907374a
commit
95aaef9aa1
@ -198,11 +198,15 @@ impl PosixTimerManager {
|
|||||||
/// Removes the POSIX timer with the ID `timer_id`.
|
/// Removes the POSIX timer with the ID `timer_id`.
|
||||||
pub fn remove_posix_timer(&self, timer_id: usize) -> Option<Arc<Timer>> {
|
pub fn remove_posix_timer(&self, timer_id: usize) -> Option<Arc<Timer>> {
|
||||||
let mut timers = self.posix_timers.lock();
|
let mut timers = self.posix_timers.lock();
|
||||||
let timer = timers[timer_id].take();
|
if timer_id < timers.len() {
|
||||||
if timer.is_some() {
|
let timer = timers[timer_id].take();
|
||||||
// Holding the lock of `posix_timers` is required to operate the `id_allocator`.
|
if timer.is_some() {
|
||||||
self.id_allocator.lock().free(timer_id);
|
// Holding the lock of `posix_timers` is required to operate the `id_allocator`.
|
||||||
|
self.id_allocator.lock().free(timer_id);
|
||||||
|
}
|
||||||
|
timer
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
timer
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user