aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/IO/AIO.h
blob: 202939638b73f9de1f23bc5fa56ffca0c00122e9 (plain) (blame)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#include <boost/noncopyable.hpp>

#if defined(OS_LINUX)

/// https://stackoverflow.com/questions/20759750/resolving-redefinition-of-timespec-in-time-h
#    define timespec linux_timespec
#    define timeval linux_timeval
#    define itimerspec linux_itimerspec
#    define sigset_t linux_sigset_t

#    include <linux/aio_abi.h>

#    undef timespec
#    undef timeval
#    undef itimerspec
#    undef sigset_t


/** Small wrappers for asynchronous I/O.
  */

int io_setup(unsigned nr, aio_context_t * ctxp);

int io_destroy(aio_context_t ctx);

/// last argument is an array of pointers technically speaking
int io_submit(aio_context_t ctx, long nr, struct iocb * iocbpp[]); /// NOLINT

int io_getevents(aio_context_t ctx, long min_nr, long max_nr, io_event * events, struct timespec * timeout); /// NOLINT


struct AIOContext : private boost::noncopyable
{
    aio_context_t ctx = 0;

    AIOContext() = default;
    explicit AIOContext(unsigned int nr_events);
    ~AIOContext();
    AIOContext(AIOContext && rhs) noexcept;
    AIOContext & operator=(AIOContext && rhs) noexcept;
};

#elif defined(OS_FREEBSD)

#    include <aio.h>
#    include <sys/event.h>
#    include <sys/time.h>
#    include <sys/types.h>

typedef struct kevent io_event;
typedef int aio_context_t;

struct iocb
{
    struct aiocb aio;
    long aio_data;
};

int io_setup(void);

int io_destroy(void);

/// last argument is an array of pointers technically speaking
int io_submit(int ctx, long nr, struct iocb * iocbpp[]);

int io_getevents(int ctx, long min_nr, long max_nr, struct kevent * events, struct timespec * timeout);


struct AIOContext : private boost::noncopyable
{
    int ctx;

    AIOContext(unsigned int nr_events = 128);
    ~AIOContext();
};

#endif