-
Notifications
You must be signed in to change notification settings - Fork 1
/
async_io.h
60 lines (50 loc) · 1.01 KB
/
async_io.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* SPDX-License-Identifier: MIT */
/*
* gcc -Wall -O2 -D_GNU_SOURCE -o io_uring-cp io_uring-cp.c -luring
*/
#ifndef ASYNC_IO_H_
#define ASYNC_IO_H_
#include <libaio.h>
#include <fcntl.h>
#ifdef ENABLE_URING
#include "liburing.h"
#endif
struct IoTask;
typedef void (*IocbFunc)(IoTask *task);
struct IoTask {
int index; // thread index
int fd;
bool isRead;
off_t first_offset, offset;
size_t first_len;
iovec iov;
int res;
IocbFunc cb;
void *arg;
};
class AsyncIo {
public:
virtual int SubmitIo(IoTask *task) { return 0; }
virtual IoTask *ReapIo() { return nullptr; }
};
#ifdef ENABLE_URING
class Uring: public AsyncIo {
public:
explicit Uring(unsigned ioDepth);
~Uring();
int SubmitIo(IoTask *task);
IoTask *ReapIo();
private:
struct io_uring ring_;
};
#endif
class Libaio: public AsyncIo {
public:
explicit Libaio(unsigned ioDepth);
~Libaio();
int SubmitIo(IoTask *task);
IoTask *ReapIo();
private:
io_context_t ctx_;
};
#endif // ASYNC_IO_H_