66 lines
1.3 KiB
C
66 lines
1.3 KiB
C
#ifndef __DISK_IOURING_H__
|
|
#define __DISK_IOURING_H__
|
|
|
|
#include <liburing.h>
|
|
#include <pthread.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdatomic.h>
|
|
|
|
typedef enum { TASK_READ, TASK_WRITE } task_op_t;
|
|
|
|
typedef struct task {
|
|
task_op_t op;
|
|
int fd;
|
|
off_t off;
|
|
|
|
int res; // cqe->res
|
|
int done; // 0/1
|
|
|
|
struct iovec *iovs; // iovec 数组
|
|
int iovcnt; // iovec 数量
|
|
|
|
struct task *next;
|
|
} task_t;
|
|
|
|
typedef struct {
|
|
_Atomic(task_t *) head;
|
|
} task_stack_t;
|
|
|
|
typedef struct {
|
|
_Atomic(task_t *) head;
|
|
} destroy_queue_t;
|
|
|
|
typedef struct {
|
|
struct io_uring ring;
|
|
pthread_t th;
|
|
|
|
int event_fd;
|
|
|
|
int stop;
|
|
_Atomic int in_flight;
|
|
int max_in_flight;
|
|
} iouring_ctx_t;
|
|
|
|
|
|
void task_init(task_t *t);
|
|
void task_finish(task_t *t, int res);
|
|
|
|
int task_wait(task_t *t);
|
|
void task_destroy(task_t *t);
|
|
|
|
int iouring_init(iouring_ctx_t *ctx, unsigned entries);
|
|
void iouring_shutdown(iouring_ctx_t *ctx);
|
|
|
|
task_t* submit_write(iouring_ctx_t *ctx, int fd, void **bufs, size_t *lens, int count, off_t off);
|
|
int uring_task_complete(iouring_ctx_t *ctx);
|
|
|
|
void cleanup_finished_iouring_tasks();
|
|
|
|
extern iouring_ctx_t global_uring_ctx;
|
|
|
|
#endif |