ClickHouse/src/IO/AIO.h

80 lines
1.7 KiB
C++
Raw Normal View History

#pragma once
2018-08-21 17:25:00 +00:00
#include <boost/noncopyable.hpp>
#if defined(OS_LINUX)
2019-02-10 17:12:22 +00:00
/// 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
2018-06-18 02:17:00 +00:00
# include <linux/aio_abi.h>
2018-06-18 02:17:00 +00:00
# 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[]);
int io_getevents(aio_context_t ctx, long min_nr, long max_nr, io_event * events, struct timespec * timeout);
struct AIOContext : private boost::noncopyable
{
2021-07-28 06:08:29 +00:00
aio_context_t ctx = 0;
2021-07-28 06:08:29 +00:00
AIOContext() {}
2021-08-24 22:07:06 +00:00
AIOContext(unsigned int nr_events);
~AIOContext();
AIOContext(AIOContext && rhs) noexcept;
AIOContext & operator=(AIOContext && rhs) noexcept;
};
#elif defined(OS_FREEBSD)
2019-02-07 15:08:45 +00:00
# include <aio.h>
# include <sys/event.h>
# include <sys/time.h>
# include <sys/types.h>
2019-02-07 15:08:45 +00:00
typedef struct kevent io_event;
typedef int aio_context_t;
2019-02-08 13:36:58 +00:00
struct iocb
{
2019-02-07 15:08:45 +00:00
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