proxygen
|
#include <AsyncIO.h>
Public Types | |
enum | PollMode { NOT_POLLABLE, POLLABLE } |
typedef AsyncIOOp | Op |
Public Member Functions | |
AsyncIO (size_t capacity, PollMode pollMode=NOT_POLLABLE) | |
~AsyncIO () | |
Range< Op ** > | wait (size_t minRequests) |
Range< Op ** > | cancel () |
size_t | pending () const |
size_t | capacity () const |
size_t | totalSubmits () const |
int | pollFd () const |
Range< Op ** > | pollCompleted () |
void | submit (Op *op) |
Private Types | |
enum | WaitType { WaitType::COMPLETE, WaitType::CANCEL } |
Private Member Functions | |
void | decrementPending () |
void | initializeContext () |
Range< AsyncIO::Op ** > | doWait (WaitType type, size_t minRequests, size_t maxRequests, std::vector< Op * > &result) |
Private Attributes | |
io_context_t | ctx_ {nullptr} |
std::atomic< bool > | ctxSet_ {false} |
std::mutex | initMutex_ |
std::atomic< size_t > | pending_ {0} |
std::atomic< size_t > | submitted_ {0} |
const size_t | capacity_ |
int | pollFd_ {-1} |
std::vector< Op * > | completed_ |
std::vector< Op * > | canceled_ |
typedef AsyncIOOp folly::AsyncIO::Op |
Enumerator | |
---|---|
NOT_POLLABLE | |
POLLABLE |
Definition at line 129 of file AsyncIO.h.
|
strongprivate |
|
explicit |
Create an AsyncIO context capable of holding at most 'capacity' pending requests at the same time. As requests complete, others can be scheduled, as long as this limit is not exceeded.
Note: the maximum number of allowed concurrent requests is controlled by the fs.aio-max-nr sysctl, the default value is usually 64K.
If pollMode is POLLABLE, pollFd() will return a file descriptor that can be passed to poll / epoll / select and will become readable when any IOs on this AsyncIO have completed. If you do this, you must use pollCompleted() instead of wait() – do not read from the pollFd() file descriptor directly.
You may use the same AsyncIO object from multiple threads, as long as there is only one concurrent caller of wait() / pollCompleted() / cancel() (perhaps by always calling it from the same thread, or by providing appropriate mutual exclusion). In this case, pending() returns a snapshot of the current number of pending requests.
Definition at line 110 of file AsyncIO.cpp.
References capacity_, folly::checkUnixError(), completed_, EFD_NONBLOCK, eventfd, POLLABLE, and pollFd_.
folly::AsyncIO::~AsyncIO | ( | ) |
Definition at line 119 of file AsyncIO.cpp.
References folly::netops::close(), ctx_, folly::errnoStr(), pending_, and pollFd_.
Range< AsyncIO::Op ** > folly::AsyncIO::cancel | ( | ) |
Cancel all pending requests and return them; the returned range is valid until the next call to cancel().
Definition at line 197 of file AsyncIO.cpp.
References CANCEL, canceled_, ctx_, doWait(), and pending_.
Referenced by TEST().
|
inline |
Return the maximum number of requests that can be kept outstanding at any one time.
Definition at line 181 of file AsyncIO.h.
Referenced by folly::AsyncIOQueue::maybeDequeue().
|
private |
Definition at line 130 of file AsyncIO.cpp.
References pending_.
Referenced by doWait(), and submit().
|
private |
Definition at line 226 of file AsyncIO.cpp.
References folly::AsyncIOOp::cancel(), CANCEL, folly::AsyncIOOp::complete(), COMPLETE, count, ctx_, decrementPending(), folly::errnoStr(), i, folly::AsyncIOOp::iocb_, and folly::range().
Referenced by cancel(), pollCompleted(), and wait().
|
private |
Definition at line 135 of file AsyncIO.cpp.
References capacity_, folly::checkKernelError(), ctx_, ctxSet_, initMutex_, and folly::lock().
Referenced by submit().
|
inline |
Return the number of pending requests.
Definition at line 173 of file AsyncIO.h.
Referenced by folly::AsyncIOQueue::maybeDequeue(), TEST(), and folly::AsyncIOQueue::~AsyncIOQueue().
Range< AsyncIO::Op ** > folly::AsyncIO::pollCompleted | ( | ) |
If POLLABLE, call instead of wait after the file descriptor returned by pollFd() became readable. The returned range is valid until the next call to pollCompleted().
Definition at line 203 of file AsyncIO.cpp.
References folly::checkUnixError(), COMPLETE, completed_, ctx_, doWait(), pending_, pollFd_, fizz::detail::read(), uint64_t, and UNLIKELY.
|
inline |
void folly::AsyncIO::submit | ( | Op * | op | ) |
Submit an op for execution.
Definition at line 164 of file AsyncIO.cpp.
References capacity_, ctx_, decrementPending(), initializeContext(), folly::AsyncIOOp::INITIALIZED, folly::AsyncIOOp::iocb_, pending_, pollFd_, folly::AsyncIOOp::start(), folly::AsyncIOOp::state(), submitted_, and folly::throwSystemErrorExplicit().
Referenced by folly::AsyncIOQueue::maybeDequeue(), and TEST().
|
inline |
Range< AsyncIO::Op ** > folly::AsyncIO::wait | ( | size_t | minRequests | ) |
Wait for at least minRequests to complete. Returns the requests that have completed; the returned range is valid until the next call to wait(). minRequests may be 0 to not block.
Definition at line 189 of file AsyncIO.cpp.
References COMPLETE, completed_, ctx_, doWait(), pending_, and pollFd_.
Referenced by TEST().
|
private |
|
private |
Definition at line 231 of file AsyncIO.h.
Referenced by AsyncIO(), initializeContext(), and submit().
|
private |
Definition at line 233 of file AsyncIO.h.
Referenced by AsyncIO(), pollCompleted(), and wait().
|
private |
Definition at line 225 of file AsyncIO.h.
Referenced by cancel(), doWait(), initializeContext(), pollCompleted(), submit(), wait(), and ~AsyncIO().
|
private |
Definition at line 226 of file AsyncIO.h.
Referenced by initializeContext().
|
private |
Definition at line 227 of file AsyncIO.h.
Referenced by initializeContext().
|
private |
Definition at line 229 of file AsyncIO.h.
Referenced by cancel(), decrementPending(), pollCompleted(), submit(), wait(), and ~AsyncIO().
|
private |
Definition at line 232 of file AsyncIO.h.
Referenced by AsyncIO(), pollCompleted(), submit(), wait(), and ~AsyncIO().
|
private |