mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 03:13:23 +00:00
Improve readability
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
95aaef9aa1
commit
90688286aa
@ -188,25 +188,25 @@ impl PosixTimerManager {
|
|||||||
/// Finds a POSIX timer by the input `timer_id`.
|
/// Finds a POSIX timer by the input `timer_id`.
|
||||||
pub fn find_posix_timer(&self, timer_id: usize) -> Option<Arc<Timer>> {
|
pub fn find_posix_timer(&self, timer_id: usize) -> Option<Arc<Timer>> {
|
||||||
let timers = self.posix_timers.lock();
|
let timers = self.posix_timers.lock();
|
||||||
if timer_id < timers.len() {
|
if timer_id >= timers.len() {
|
||||||
timers[timer_id].clone()
|
return None;
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timers[timer_id].clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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();
|
||||||
if timer_id < timers.len() {
|
if timer_id >= timers.len() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let timer = timers[timer_id].take();
|
let timer = timers[timer_id].take();
|
||||||
if timer.is_some() {
|
if timer.is_some() {
|
||||||
// Holding the lock of `posix_timers` is required to operate the `id_allocator`.
|
// Holding the lock of `posix_timers` is required to operate the `id_allocator`.
|
||||||
self.id_allocator.lock().free(timer_id);
|
self.id_allocator.lock().free(timer_id);
|
||||||
}
|
}
|
||||||
timer
|
timer
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user