2018-06-18 01:33:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-08-21 17:25:00 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
|
2020-04-07 08:33:49 +00:00
|
|
|
#if defined(OS_LINUX)
|
2019-02-10 17:12:22 +00:00
|
|
|
|
2018-06-18 01:33:34 +00:00
|
|
|
/// https://stackoverflow.com/questions/20759750/resolving-redefinition-of-timespec-in-time-h
|
2020-04-07 08:33:49 +00:00
|
|
|
# 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
|
|
|
|
2020-04-07 08:33:49 +00:00
|
|
|
# include <linux/aio_abi.h>
|
2018-06-18 02:17:00 +00:00
|
|
|
|
2020-04-07 08:33:49 +00:00
|
|
|
# undef timespec
|
|
|
|
# undef timeval
|
|
|
|
# undef itimerspec
|
|
|
|
# undef sigset_t
|
2018-06-18 01:33:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** 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
|
2022-03-13 11:59:20 +00:00
|
|
|
int io_submit(aio_context_t ctx, long nr, struct iocb * iocbpp[]); /// NOLINT
|
2018-06-18 01:33:34 +00:00
|
|
|
|
2022-03-13 11:59:20 +00:00
|
|
|
int io_getevents(aio_context_t ctx, long min_nr, long max_nr, io_event * events, struct timespec * timeout); /// NOLINT
|
2018-06-18 01:33:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct AIOContext : private boost::noncopyable
|
|
|
|
{
|
2021-07-28 06:08:29 +00:00
|
|
|
aio_context_t ctx = 0;
|
2018-06-18 01:33:34 +00:00
|
|
|
|
2022-03-13 11:59:20 +00:00
|
|
|
AIOContext() = default;
|
|
|
|
explicit AIOContext(unsigned int nr_events);
|
2018-06-18 01:33:34 +00:00
|
|
|
~AIOContext();
|
2022-02-25 19:04:48 +00:00
|
|
|
AIOContext(AIOContext && rhs) noexcept;
|
|
|
|
AIOContext & operator=(AIOContext && rhs) noexcept;
|
2018-06-18 01:33:34 +00:00
|
|
|
};
|
|
|
|
|
2020-04-07 08:33:49 +00:00
|
|
|
#elif defined(OS_FREEBSD)
|
2019-02-07 15:08:45 +00:00
|
|
|
|
2020-04-07 08:33:49 +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();
|
|
|
|
};
|
|
|
|
|
2018-06-18 01:33:34 +00:00
|
|
|
#endif
|