/** * @file ioqueue.h * @author simon (ynwdlxm@163.com) * @brief 环形缓冲区队列 * @version 0.1 * @date 2025-01-11 * * @copyright Copyright (c) 2025 * */ #ifndef __DEVICE_IOQUEUE_H #define __DEVICE_IOQUEUE_H #include "../lib/stdint.h" #include "../thread/thread.h" #include "../thread/sync.h" #define BUF_SIZE 64 /* 环形队列 */ struct ioqueue { struct lock lock; // 锁,用于同步 struct task_struct *producer; // 记录哪个生产者在此缓冲区睡眠 struct task_struct *consumer; // 记录哪个消费者在此缓冲区睡眠 char buf[BUF_SIZE]; // 缓冲区大小 int32_t head; // 队首,数据往队首处写入 int32_t tail; // 队尾,数据从队尾处读出 }; /// @brief 初始化 ioqueue 队列 /// @param ioq void ioqueue_init(struct ioqueue *ioq); /// @brief 判断队列是否已满 /// @param ioq /// @return TRUE OR FALSE bool ioq_full(struct ioqueue *ioq); /// @brief 判断队列是否为空 /// @param ioq /// @return TRUE OR FALSE bool ioq_empty(struct ioqueue *ioq); /// @brief 消费者从 ioq 队列中获取一个字符 char ioq_getchar(struct ioqueue *ioq); /// @brief 生产者往 ioq 队列中添加一个字符 void ioq_putchar(struct ioqueue *ioq, char byte); #endif //!__DEVICE_IOQUEUE_H