1 Star 0 Fork 3

gaoxuelong / fio

forked from HoperunHarmony / fio 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
io_u_queue.h 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
董森浩 提交于 2022-08-08 15:05 . 原版fio3.30
#ifndef FIO_IO_U_QUEUE
#define FIO_IO_U_QUEUE
#include <assert.h>
#include <stddef.h>
#include "lib/types.h"
struct io_u;
struct io_u_queue {
struct io_u **io_us;
unsigned int nr;
unsigned int max;
};
static inline struct io_u *io_u_qpop(struct io_u_queue *q)
{
if (q->nr) {
const unsigned int next = --q->nr;
struct io_u *io_u = q->io_us[next];
q->io_us[next] = NULL;
return io_u;
}
return NULL;
}
static inline void io_u_qpush(struct io_u_queue *q, struct io_u *io_u)
{
if (q->nr < q->max) {
q->io_us[q->nr++] = io_u;
return;
}
assert(0);
}
static inline int io_u_qempty(const struct io_u_queue *q)
{
return !q->nr;
}
#define io_u_qiter(q, io_u, i) \
for (i = 0; i < (q)->nr && (io_u = (q)->io_us[i]); i++)
bool io_u_qinit(struct io_u_queue *q, unsigned int nr, bool shared);
void io_u_qexit(struct io_u_queue *q, bool shared);
struct io_u_ring {
unsigned int head;
unsigned int tail;
unsigned int max;
struct io_u **ring;
};
bool io_u_rinit(struct io_u_ring *ring, unsigned int nr);
void io_u_rexit(struct io_u_ring *ring);
static inline void io_u_rpush(struct io_u_ring *r, struct io_u *io_u)
{
if (r->head + 1 != r->tail) {
r->ring[r->head] = io_u;
r->head = (r->head + 1) & (r->max - 1);
return;
}
assert(0);
}
static inline struct io_u *io_u_rpop(struct io_u_ring *r)
{
if (r->head != r->tail) {
struct io_u *io_u = r->ring[r->tail];
r->tail = (r->tail + 1) & (r->max - 1);
return io_u;
}
return NULL;
}
static inline int io_u_rempty(struct io_u_ring *ring)
{
return ring->head == ring->tail;
}
#endif
1
https://gitee.com/gaoxuelong/fio.git
git@gitee.com:gaoxuelong/fio.git
gaoxuelong
fio
fio
master

搜索帮助