68 lines
1.3 KiB
C
68 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>
|
|
|
|
|
|
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 数量
|
|
|
|
pthread_mutex_t m;
|
|
pthread_cond_t cv;
|
|
|
|
struct task *next;
|
|
} task_t;
|
|
|
|
typedef struct {
|
|
struct io_uring ring;
|
|
pthread_t th;
|
|
|
|
pthread_mutex_t q_m;
|
|
pthread_cond_t q_cv;
|
|
task_t *q_head, *q_tail;
|
|
|
|
int stop;
|
|
atomic_int in_flight;
|
|
int max_in_flight;
|
|
} iouring_ctx_t;
|
|
|
|
typedef struct {
|
|
task_t *head;
|
|
pthread_mutex_t lock;
|
|
} destroy_queue_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 |