n*spsc uring_pool
This commit is contained in:
@@ -3,13 +3,13 @@
|
||||
|
||||
#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>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef enum { TASK_READ, TASK_WRITE } task_op_t;
|
||||
|
||||
@@ -18,49 +18,64 @@ typedef struct task {
|
||||
int fd;
|
||||
off_t off;
|
||||
|
||||
int res; // cqe->res
|
||||
int done; // 0/1
|
||||
int res;
|
||||
_Atomic int done;
|
||||
|
||||
struct iovec *iovs; // iovec 数组
|
||||
int iovcnt; // iovec 数量
|
||||
struct iovec *iovs;
|
||||
int iovcnt;
|
||||
|
||||
struct task *next;
|
||||
} task_t;
|
||||
|
||||
typedef struct {
|
||||
_Atomic(task_t *) head;
|
||||
} task_stack_t;
|
||||
} destroy_queue_t;
|
||||
|
||||
typedef struct {
|
||||
_Atomic(task_t *) head;
|
||||
} destroy_queue_t;
|
||||
task_t **slots;
|
||||
uint32_t cap;
|
||||
_Atomic uint32_t head;
|
||||
_Atomic uint32_t tail;
|
||||
_Atomic uint32_t size;
|
||||
} spsc_queue_t;
|
||||
|
||||
struct iouring_ctx_s;
|
||||
typedef struct iouring_ctx_s iouring_ctx_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;
|
||||
int max_in_flight;
|
||||
int worker_id;
|
||||
spsc_queue_t submit_q;
|
||||
iouring_ctx_t *parent;
|
||||
} iouring_worker_t;
|
||||
|
||||
struct iouring_ctx_s {
|
||||
iouring_worker_t *workers;
|
||||
int worker_nr;
|
||||
unsigned entries_per_worker;
|
||||
|
||||
_Atomic int stop;
|
||||
_Atomic uint32_t rr_next;
|
||||
|
||||
destroy_queue_t destroy_queue;
|
||||
};
|
||||
|
||||
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);
|
||||
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();
|
||||
void cleanup_finished_iouring_tasks(iouring_ctx_t *ctx);
|
||||
|
||||
extern iouring_ctx_t global_uring_ctx;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user