mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-21 22:43:23 +00:00
添加completion模块+wait_queue_head模块+schedule_timeout (#70)
* 添加completion模块+wait_queue_head模块+schedule_timeout * 修复一些bug * 实现设置pcb名字和vsnprintf (#72) * 实现pcb设置名字 * 实现设置pcb名字,实现vsnprintf * 修改set_pcb_name和va_end * bugfix: 修正一些小问题 Co-authored-by: longjin <longjin@RinGoTek.cn> * new: FAT32删除文件的功能 (#73) * new: 将sys_rmdir更改为sys_unlink,.且完成删除文件操作的vfs部分 * new: fat32删除文件 *bugfix: 解决创建文件时的bug * new: 将可执行文件移动到bin目录下 * 完善completion和wait_queue_head文档,并确保测试ok。 Co-authored-by: longjin <longjin@RinGoTek.cn> Co-authored-by: houmkh <100781004+houmkh@users.noreply.github.com>
This commit is contained in:
82
kernel/lib/wait_queue_head.c
Normal file
82
kernel/lib/wait_queue_head.c
Normal file
@ -0,0 +1,82 @@
|
||||
#include <common/wait_queue_head.h>
|
||||
#include <process/process.h>
|
||||
#include <sched/sched.h>
|
||||
|
||||
/**
|
||||
* @brief 初始化等待队列
|
||||
*
|
||||
* @param wait_queue 等待队列
|
||||
* @param pcb pcb
|
||||
*/
|
||||
void wait_queue_head_init(wait_queue_head_t *wait_queue)
|
||||
{
|
||||
list_init(&wait_queue->wait_list);
|
||||
spin_init(&wait_queue->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 在等待队列上进行等待, 但是你需要确保wait已经被init, 同时wakeup只能使用wake_up_on_stack函数。
|
||||
*
|
||||
* @param wait_queue_head 队列头指针
|
||||
*/
|
||||
void wait_queue_sleep_with_node(wait_queue_head_t *q, wait_queue_node_t *wait)
|
||||
{
|
||||
BUG_ON(wait->pcb == NULL);
|
||||
|
||||
wait->pcb->state = PROC_UNINTERRUPTIBLE;
|
||||
list_append(&q->wait_list, &wait->wait_list);
|
||||
|
||||
sched();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 在等待队列上进行等待,同时释放自旋锁, 但是你需要确保wait已经被init, 同时wakeup只能使用wake_up_on_stack函数。
|
||||
*
|
||||
* @param wait_queue_head 队列头指针
|
||||
*/
|
||||
void wait_queue_sleep_with_node_unlock(wait_queue_head_t *q, wait_queue_node_t *wait, void *lock)
|
||||
{
|
||||
BUG_ON(wait->pcb == NULL);
|
||||
|
||||
wait->pcb->state = PROC_UNINTERRUPTIBLE;
|
||||
list_append(&q->wait_list, &wait->wait_list);
|
||||
spin_unlock((spinlock_t *)lock);
|
||||
|
||||
sched();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 在等待队列上进行等待(允许中断), 但是你需要确保wait已经被init, 同时wakeup只能使用wake_up_on_stack函数。
|
||||
*
|
||||
* @param wait_queue_head 队列头指针
|
||||
*/
|
||||
void wait_queue_sleep_with_node_interriptible(wait_queue_head_t *q, wait_queue_node_t *wait)
|
||||
{
|
||||
BUG_ON(wait->pcb == NULL);
|
||||
|
||||
wait->pcb->state = PROC_INTERRUPTIBLE;
|
||||
list_append(&q->wait_list, &wait->wait_list);
|
||||
|
||||
sched();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 唤醒在等待队列的头部的进程, 但是不会free掉这个节点的空间(默认这个节点在栈上创建)
|
||||
*
|
||||
* @param wait_queue_head
|
||||
* @param state
|
||||
*/
|
||||
void wait_queue_wakeup_on_stack(wait_queue_head_t *q, int64_t state)
|
||||
{
|
||||
if (list_empty(&q->wait_list))
|
||||
return;
|
||||
|
||||
wait_queue_node_t *wait = container_of(list_next(&q->wait_list), wait_queue_node_t, wait_list);
|
||||
|
||||
// 符合唤醒条件
|
||||
if (wait->pcb->state & state)
|
||||
{
|
||||
list_del_init(&wait->wait_list);
|
||||
process_wakeup(wait->pcb);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user