proxygen
folly::AsyncIOQueue Class Reference

#include <AsyncIO.h>

Public Types

typedef std::function< AsyncIOOp *()> OpFactory
 

Public Member Functions

 AsyncIOQueue (AsyncIO *asyncIO)
 
 ~AsyncIOQueue ()
 
size_t queued () const
 
void submit (AsyncIOOp *op)
 
void submit (OpFactory op)
 

Private Member Functions

void onCompleted (AsyncIOOp *op)
 
void maybeDequeue ()
 

Private Attributes

AsyncIOasyncIO_
 
std::deque< OpFactoryqueue_
 

Detailed Description

Wrapper around AsyncIO that allows you to schedule more requests than the AsyncIO's object capacity. Other requests are queued and processed in a FIFO order.

Definition at line 242 of file AsyncIO.h.

Member Typedef Documentation

typedef std::function<AsyncIOOp*()> folly::AsyncIOQueue::OpFactory

Submit a delayed op to the AsyncIO queue; this allows you to postpone creation of the Op (which may require allocating memory, etc) until the AsyncIO object has room.

Definition at line 267 of file AsyncIO.h.

Constructor & Destructor Documentation

folly::AsyncIOQueue::AsyncIOQueue ( AsyncIO asyncIO)
explicit

Create a queue, using the given AsyncIO object. The AsyncIO object may not be used by anything else until the queue is destroyed.

Definition at line 276 of file AsyncIO.cpp.

276 : asyncIO_(asyncIO) {}
AsyncIO * asyncIO_
Definition: AsyncIO.h:274
folly::AsyncIOQueue::~AsyncIOQueue ( )

Definition at line 278 of file AsyncIO.cpp.

References asyncIO_, and folly::AsyncIO::pending().

278  {
279  CHECK_EQ(asyncIO_->pending(), 0);
280 }
AsyncIO * asyncIO_
Definition: AsyncIO.h:274
size_t pending() const
Definition: AsyncIO.h:173

Member Function Documentation

void folly::AsyncIOQueue::maybeDequeue ( )
private

Definition at line 295 of file AsyncIO.cpp.

References asyncIO_, folly::AsyncIO::capacity(), onCompleted(), folly::AsyncIO::pending(), queue_, and folly::AsyncIO::submit().

Referenced by onCompleted(), and submit().

295  {
296  while (!queue_.empty() && asyncIO_->pending() < asyncIO_->capacity()) {
297  auto& opFactory = queue_.front();
298  auto op = opFactory();
299  queue_.pop_front();
300 
301  // Interpose our completion callback
302  auto& nextCb = op->notificationCallback();
303  op->setNotificationCallback([this, nextCb](AsyncIOOp* op2) {
304  this->onCompleted(op2);
305  if (nextCb) {
306  nextCb(op2);
307  }
308  });
309 
310  asyncIO_->submit(op);
311  }
312 }
AsyncIO * asyncIO_
Definition: AsyncIO.h:274
size_t pending() const
Definition: AsyncIO.h:173
std::deque< OpFactory > queue_
Definition: AsyncIO.h:276
void submit(Op *op)
Definition: AsyncIO.cpp:164
void onCompleted(AsyncIOOp *op)
Definition: AsyncIO.cpp:291
size_t capacity() const
Definition: AsyncIO.h:181
void folly::AsyncIOQueue::onCompleted ( AsyncIOOp op)
private

Definition at line 291 of file AsyncIO.cpp.

References maybeDequeue().

Referenced by maybeDequeue().

291  {
292  maybeDequeue();
293 }
size_t folly::AsyncIOQueue::queued ( ) const
inline

Definition at line 252 of file AsyncIO.h.

References submit.

252  {
253  return queue_.size();
254  }
std::deque< OpFactory > queue_
Definition: AsyncIO.h:276
void folly::AsyncIOQueue::submit ( AsyncIOOp op)

Submit an op to the AsyncIO queue. The op will be queued until the AsyncIO object has room.

Definition at line 282 of file AsyncIO.cpp.

282  {
283  submit([op]() { return op; });
284 }
void submit(AsyncIOOp *op)
Definition: AsyncIO.cpp:282
void folly::AsyncIOQueue::submit ( OpFactory  op)

Definition at line 286 of file AsyncIO.cpp.

References maybeDequeue(), and queue_.

286  {
287  queue_.push_back(op);
288  maybeDequeue();
289 }
std::deque< OpFactory > queue_
Definition: AsyncIO.h:276

Member Data Documentation

AsyncIO* folly::AsyncIOQueue::asyncIO_
private

Definition at line 274 of file AsyncIO.h.

Referenced by maybeDequeue(), and ~AsyncIOQueue().

std::deque<OpFactory> folly::AsyncIOQueue::queue_
private

Definition at line 276 of file AsyncIO.h.

Referenced by maybeDequeue(), and submit().


The documentation for this class was generated from the following files: