ioqueue.c
#include "ioqueue.h"
#include "../task/task.h"
#include "../debug/debug.h"
extern struct task_struct *current;
/* 初始化io队列ioq */
void ioqueue_init(struct ioqueue* ioq) {
lock_init(&ioq->lock); // 初始化io队列的锁
ioq->producer = ioq->consumer = NULL; // 生产者和消费者置空
ioq->head = ioq->tail = 0; // 队列的首尾指针指向缓冲区数组第0个位置
}
/* 返回pos在缓冲区中的下一个位置值 */
static int next_pos(int pos) {
return (pos + 1) % bufsize;
}
/* 判断队列是否已满 */
char ioq_full(struct ioqueue* ioq) {
//ASSERT(get_now_intr_status() == INTR_OFF);
return next_pos(ioq->head) == ioq->tail;
}
/* 判断队列是否已空 */
static char ioq_empty(struct ioqueue* ioq) {
//ASSERT(get_now_intr_status() == INTR_OFF);
return ioq->head == ioq->tail;
}
/* 使当前生产者或消费者在此缓冲区上等待 */
static void ioq_wait(struct task_struct** waiter) {
ASSERT(*waiter == NULL && waiter !=