mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 02:46:47 +00:00
* 添加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>
84 lines
2.2 KiB
C
84 lines
2.2 KiB
C
#include <common/spinlock.h>
|
|
#include <common/wait_queue.h>
|
|
#include <mm/slab.h>
|
|
#include <process/process.h>
|
|
#include <sched/sched.h>
|
|
|
|
/**
|
|
* @brief 初始化等待队列
|
|
*
|
|
* @param wait_queue 等待队列
|
|
* @param pcb pcb
|
|
*/
|
|
void wait_queue_init(wait_queue_node_t *wait_queue, struct process_control_block *pcb)
|
|
{
|
|
list_init(&wait_queue->wait_list);
|
|
wait_queue->pcb = pcb;
|
|
}
|
|
|
|
/**
|
|
* @brief 在等待队列上进行等待
|
|
*
|
|
* @param wait_queue_head 队列头指针
|
|
*/
|
|
void wait_queue_sleep_on(wait_queue_node_t *wait_queue_head)
|
|
{
|
|
wait_queue_node_t *wait = (wait_queue_node_t *)kzalloc(sizeof(wait_queue_node_t), 0);
|
|
wait_queue_init(wait, current_pcb);
|
|
current_pcb->state = PROC_UNINTERRUPTIBLE;
|
|
list_append(&wait_queue_head->wait_list, &wait->wait_list);
|
|
|
|
sched();
|
|
}
|
|
|
|
/**
|
|
* @brief 在等待队列上进行等待,同时释放自旋锁
|
|
*
|
|
* @param wait_queue_head 队列头指针
|
|
*/
|
|
void wait_queue_sleep_on_unlock(wait_queue_node_t *wait_queue_head,
|
|
void *lock)
|
|
{
|
|
wait_queue_node_t *wait = (wait_queue_node_t *)kzalloc(sizeof(wait_queue_node_t), 0);
|
|
wait_queue_init(wait, current_pcb);
|
|
current_pcb->state = PROC_UNINTERRUPTIBLE;
|
|
list_append(&wait_queue_head->wait_list, &wait->wait_list);
|
|
spin_unlock((spinlock_t *)lock);
|
|
sched();
|
|
}
|
|
|
|
/**
|
|
* @brief 在等待队列上进行等待(允许中断)
|
|
*
|
|
* @param wait_queue_head 队列头指针
|
|
*/
|
|
void wait_queue_sleep_on_interriptible(wait_queue_node_t *wait_queue_head)
|
|
{
|
|
wait_queue_node_t *wait = (wait_queue_node_t *)kzalloc(sizeof(wait_queue_node_t), 0);
|
|
wait_queue_init(wait, current_pcb);
|
|
current_pcb->state = PROC_INTERRUPTIBLE;
|
|
list_append(&wait_queue_head->wait_list, &wait->wait_list);
|
|
|
|
sched();
|
|
}
|
|
|
|
/**
|
|
* @brief 唤醒在等待队列的头部的进程
|
|
*
|
|
* @param wait_queue_head
|
|
* @param state
|
|
*/
|
|
void wait_queue_wakeup(wait_queue_node_t *wait_queue_head, int64_t state)
|
|
{
|
|
if (list_empty(&wait_queue_head->wait_list))
|
|
return;
|
|
wait_queue_node_t *wait = container_of(list_next(&wait_queue_head->wait_list), wait_queue_node_t, wait_list);
|
|
|
|
// 符合唤醒条件
|
|
if (wait->pcb->state & state)
|
|
{
|
|
list_del(&wait->wait_list);
|
|
process_wakeup(wait->pcb);
|
|
kfree(wait);
|
|
}
|
|
} |