添加thread和futex机制 (#411)

* 初步实现clone系统调用

* 实现了线程,初步实现futex机制,添加了几个小的系统调用

* 更改pcb引用计数问题

* 解决死锁bug

---------

Co-authored-by: LoGin <longjin@DragonOS.org>
This commit is contained in:
GnoCiYeH
2023-11-01 20:55:57 +08:00
committed by GitHub
parent 665f4a7707
commit 971462be94
25 changed files with 1643 additions and 149 deletions

View File

@ -72,6 +72,7 @@ impl Timer {
expire_jiffies,
timer_func,
self_ref: Weak::default(),
triggered: false,
})));
result.0.lock().self_ref = Arc::downgrade(&result);
@ -112,7 +113,9 @@ impl Timer {
#[inline]
fn run(&self) {
let r = self.0.lock().timer_func.run();
let mut timer = self.0.lock();
timer.triggered = true;
let r = timer.timer_func.run();
if unlikely(r.is_err()) {
kerror!(
"Failed to run timer function: {self:?} {:?}",
@ -120,6 +123,19 @@ impl Timer {
);
}
}
/// ## 判断定时器是否已经触发
pub fn timeout(&self) -> bool {
self.0.lock().triggered
}
/// ## 取消定时器任务
pub fn cancel(&self) -> bool {
TIMER_LIST
.lock()
.drain_filter(|x| Arc::<Timer>::as_ptr(&x) == self as *const Timer);
true
}
}
/// 定时器类型
@ -131,6 +147,8 @@ pub struct InnerTimer {
pub timer_func: Box<dyn TimerFunction>,
/// self_ref
self_ref: Weak<Timer>,
/// 判断该计时器是否触发
triggered: bool,
}
#[derive(Debug)]