Apply clang-format to folly/experimental/io/
[folly.git] / folly / experimental / io / AsyncIO.cpp
index 0b51128aed74d846f80f3026baf0a7fc894776fc..59dc866c2d0dbe66f2585674fdd4368b0d8c4c31 100644 (file)
@@ -34,9 +34,7 @@
 namespace folly {
 
 AsyncIOOp::AsyncIOOp(NotificationCallback cb)
-  : cb_(std::move(cb)),
-    state_(State::UNINITIALIZED),
-    result_(-EINVAL) {
+    : cb_(std::move(cb)), state_(State::UNINITIALIZED), result_(-EINVAL) {
   memset(&iocb_, 0, sizeof(iocb_));
 }
 
@@ -142,13 +140,13 @@ void AsyncIO::initializeContext() {
       // returns negative errno
       if (rc == -EAGAIN) {
         long aio_nr, aio_max;
-        std::unique_ptr<FILE, int(*)(FILE*)>
-          fp(fopen("/proc/sys/fs/aio-nr", "r"), fclose);
+        std::unique_ptr<FILE, int (*)(FILE*)> fp(
+            fopen("/proc/sys/fs/aio-nr", "r"), fclose);
         PCHECK(fp);
         CHECK_EQ(fscanf(fp.get(), "%ld", &aio_nr), 1);
 
-        std::unique_ptr<FILE, int(*)(FILE*)>
-          aio_max_fp(fopen("/proc/sys/fs/aio-max-nr", "r"), fclose);
+        std::unique_ptr<FILE, int (*)(FILE*)> aio_max_fp(
+            fopen("/proc/sys/fs/aio-max-nr", "r"), fclose);
         PCHECK(aio_max_fp);
         CHECK_EQ(fscanf(aio_max_fp.get(), "%ld", &aio_max), 1);
 
@@ -165,7 +163,7 @@ void AsyncIO::initializeContext() {
 
 void AsyncIO::submit(Op* op) {
   CHECK_EQ(op->state(), Op::State::INITIALIZED);
-  initializeContext();  // on demand
+  initializeContext(); // on demand
 
   // We can increment past capacity, but we'll clean up after ourselves.
   auto p = pending_.fetch_add(1, std::memory_order_acq_rel);
@@ -174,7 +172,7 @@ void AsyncIO::submit(Op* op) {
     throw std::range_error("AsyncIO: too many pending requests");
   }
   iocb* cb = &op->iocb_;
-  cb->data = nullptr;  // unused
+  cb->data = nullptr; // unused
   if (pollFd_ != -1) {
     io_set_eventfd(cb, pollFd_);
   }
@@ -213,7 +211,7 @@ Range<AsyncIO::Op**> AsyncIO::pollCompleted() {
     rc = ::read(pollFd_, &numEvents, 8);
   } while (rc == -1 && errno == EINTR);
   if (UNLIKELY(rc == -1 && errno == EAGAIN)) {
-    return Range<Op**>();  // nothing completed
+    return Range<Op**>(); // nothing completed
   }
   checkUnixError(rc, "AsyncIO: read from event fd failed");
   DCHECK_EQ(rc, 8);
@@ -241,11 +239,12 @@ Range<AsyncIO::Op**> AsyncIO::doWait(
       // GOTCHA: io_getevents() may returns less than min_nr results if
       // interrupted after some events have been read (if before, -EINTR
       // is returned).
-      ret = io_getevents(ctx_,
-                         minRequests - count,
-                         maxRequests - count,
-                         events + count,
-                         /* timeout */ nullptr);  // wait forever
+      ret = io_getevents(
+          ctx_,
+          minRequests - count,
+          maxRequests - count,
+          events + count,
+          /* timeout */ nullptr); // wait forever
     } while (ret == -EINTR);
     // Check as may not be able to recover without leaking events.
     CHECK_GE(ret, 0) << "AsyncIO: io_getevents failed with error "
@@ -274,9 +273,7 @@ Range<AsyncIO::Op**> AsyncIO::doWait(
   return range(result);
 }
 
-AsyncIOQueue::AsyncIOQueue(AsyncIO* asyncIO)
-  : asyncIO_(asyncIO) {
-}
+AsyncIOQueue::AsyncIOQueue(AsyncIO* asyncIO) : asyncIO_(asyncIO) {}
 
 AsyncIOQueue::~AsyncIOQueue() {
   CHECK_EQ(asyncIO_->pending(), 0);
@@ -291,7 +288,9 @@ void AsyncIOQueue::submit(OpFactory op) {
   maybeDequeue();
 }
 
-void AsyncIOQueue::onCompleted(AsyncIOOp* /* op */) { maybeDequeue(); }
+void AsyncIOQueue::onCompleted(AsyncIOOp* /* op */) {
+  maybeDequeue();
+}
 
 void AsyncIOQueue::maybeDequeue() {
   while (!queue_.empty() && asyncIO_->pending() < asyncIO_->capacity()) {
@@ -303,7 +302,9 @@ void AsyncIOQueue::maybeDequeue() {
     auto& nextCb = op->notificationCallback();
     op->setNotificationCallback([this, nextCb](AsyncIOOp* op2) {
       this->onCompleted(op2);
-      if (nextCb) nextCb(op2);
+      if (nextCb) {
+        nextCb(op2);
+      }
     });
 
     asyncIO_->submit(op);
@@ -314,7 +315,9 @@ void AsyncIOQueue::maybeDequeue() {
 
 namespace {
 
-#define X(c) case c: return #c
+#define X(c) \
+  case c:    \
+    return #c
 
 const char* asyncIoOpStateToString(AsyncIOOp::State state) {
   switch (state) {
@@ -348,21 +351,28 @@ std::string fd2name(int fd) {
   std::string path = folly::to<std::string>("/proc/self/fd/", fd);
   char link[PATH_MAX];
   const ssize_t length =
-    std::max<ssize_t>(readlink(path.c_str(), link, PATH_MAX), 0);
+      std::max<ssize_t>(readlink(path.c_str(), link, PATH_MAX), 0);
   return path.assign(link, length);
 }
 
 std::ostream& operator<<(std::ostream& os, const iocb& cb) {
   os << folly::format(
-    "data={}, key={}, opcode={}, reqprio={}, fd={}, f={}, ",
-    cb.data, cb.key, iocbCmdToString(cb.aio_lio_opcode),
-    cb.aio_reqprio, cb.aio_fildes, fd2name(cb.aio_fildes));
+      "data={}, key={}, opcode={}, reqprio={}, fd={}, f={}, ",
+      cb.data,
+      cb.key,
+      iocbCmdToString(cb.aio_lio_opcode),
+      cb.aio_reqprio,
+      cb.aio_fildes,
+      fd2name(cb.aio_fildes));
 
   switch (cb.aio_lio_opcode) {
     case IO_CMD_PREAD:
     case IO_CMD_PWRITE:
-      os << folly::format("buf={}, offset={}, nbytes={}, ",
-                          cb.u.c.buf, cb.u.c.offset, cb.u.c.nbytes);
+      os << folly::format(
+          "buf={}, offset={}, nbytes={}, ",
+          cb.u.c.buf,
+          cb.u.c.offset,
+          cb.u.c.nbytes);
       break;
     default:
       os << "[TODO: write debug string for "
@@ -373,7 +383,7 @@ std::ostream& operator<<(std::ostream& os, const iocb& cb) {
   return os;
 }
 
-}  // anonymous namespace
+} // anonymous namespace
 
 std::ostream& operator<<(std::ostream& os, const AsyncIOOp& op) {
   os << "{" << op.state_ << ", ";
@@ -397,4 +407,4 @@ std::ostream& operator<<(std::ostream& os, AsyncIOOp::State state) {
   return os << asyncIoOpStateToString(state);
 }
 
-}  // namespace folly
+} // namespace folly