Commit f7920221 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Apply clang-format to folly/experimental/io/

Summary: [Folly] Apply `clang-format` to `folly/experimental/io/`.

Reviewed By: Orvid

Differential Revision: D5460571

fbshipit-source-id: d19aff829316dd277e65620196e12db8cad46787
parent 1804caee
......@@ -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);
......@@ -241,7 +239,8 @@ 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_,
ret = io_getevents(
ctx_,
minRequests - count,
maxRequests - count,
events + count,
......@@ -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) {
......@@ -355,14 +358,21 @@ std::string fd2name(int fd) {
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));
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 "
......
......@@ -77,7 +77,9 @@ class AsyncIOOp : private boost::noncopyable {
/**
* Return the current operation state.
*/
State state() const { return state_; }
State state() const {
return state_;
}
/**
* Reset the operation for reuse. It is an error to call reset() on
......@@ -85,8 +87,12 @@ class AsyncIOOp : private boost::noncopyable {
*/
void reset(NotificationCallback cb = NotificationCallback());
void setNotificationCallback(NotificationCallback cb) { cb_ = std::move(cb); }
const NotificationCallback& notificationCallback() const { return cb_; }
void setNotificationCallback(NotificationCallback cb) {
cb_ = std::move(cb);
}
const NotificationCallback& notificationCallback() const {
return cb_;
}
/**
* Retrieve the result of this operation. Returns >=0 on success,
......@@ -164,26 +170,34 @@ class AsyncIO : private boost::noncopyable {
/**
* Return the number of pending requests.
*/
size_t pending() const { return pending_; }
size_t pending() const {
return pending_;
}
/**
* Return the maximum number of requests that can be kept outstanding
* at any one time.
*/
size_t capacity() const { return capacity_; }
size_t capacity() const {
return capacity_;
}
/**
* Return the accumulative number of submitted I/O, since this object
* has been created.
*/
size_t totalSubmits() const { return submitted_; }
size_t totalSubmits() const {
return submitted_;
}
/**
* If POLLABLE, return a file descriptor that can be passed to poll / epoll
* and will become readable when any async IO operations have completed.
* If NOT_POLLABLE, return -1.
*/
int pollFd() const { return pollFd_; }
int pollFd() const {
return pollFd_;
}
/**
* If POLLABLE, call instead of wait after the file descriptor returned
......@@ -235,7 +249,9 @@ class AsyncIOQueue {
explicit AsyncIOQueue(AsyncIO* asyncIO);
~AsyncIOQueue();
size_t queued() const { return queue_.size(); }
size_t queued() const {
return queue_.size();
}
/**
* Submit an op to the AsyncIO queue. The op will be queued until
......
......@@ -52,7 +52,8 @@ path remove_prefix(const path& pth, const path& prefix) {
if (!skipPrefix(pth, prefix, it)) {
throw filesystem_error(
"Path does not start with prefix",
pth, prefix,
pth,
prefix,
bsys::errc::make_error_code(bsys::errc::invalid_argument));
}
......
......@@ -58,14 +58,17 @@ void list() {
} // namespace
int main(int argc, char *argv[]) {
int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
if (FLAGS_cp) {
if (argc != 3) usage(argv[0]);
if (argc != 3) {
usage(argv[0]);
}
copy(argv[1], argv[2]);
} else {
if (argc != 1) usage(argv[0]);
if (argc != 1) {
usage(argv[0]);
}
list();
}
return 0;
......
......@@ -50,8 +50,7 @@ size_t getDefaultHugePageSize() {
size_t pageSize = 0;
boost::cmatch match;
bool error = gen::byLine("/proc/meminfo") |
[&] (StringPiece line) -> bool {
bool error = gen::byLine("/proc/meminfo") | [&](StringPiece line) -> bool {
if (boost::regex_match(line.begin(), line.end(), match, regex)) {
StringPiece numStr(
line.begin() + match.position(1), size_t(match.length(1)));
......@@ -172,8 +171,8 @@ HugePageSizeVec readHugePageSizes() {
break;
}
auto pos = std::lower_bound(sizeVec.begin(), sizeVec.end(), pageSize,
PageSizeLess());
auto pos = std::lower_bound(
sizeVec.begin(), sizeVec.end(), pageSize, PageSizeLess());
if (pos == sizeVec.end() || pos->size != pageSize) {
throw std::runtime_error("Mount page size not found");
}
......
......@@ -32,7 +32,7 @@
namespace folly {
struct HugePageSize : private boost::totally_ordered<HugePageSize> {
explicit HugePageSize(size_t s) : size(s) { }
explicit HugePageSize(size_t s) : size(s) {}
fs::path filePath(const fs::path& relpath) const {
return mountPoint / relpath;
......
......@@ -80,7 +80,9 @@ class TemporaryFile {
explicit TemporaryFile(size_t size);
~TemporaryFile();
const fs::path path() const { return path_; }
const fs::path path() const {
return path_;
}
private:
fs::path path_;
......@@ -120,7 +122,7 @@ TemporaryFile::~TemporaryFile() {
TemporaryFile tempFile(6 << 20); // 6MiB
typedef std::unique_ptr<char, void(*)(void*)> ManagedBuffer;
typedef std::unique_ptr<char, void (*)(void*)> ManagedBuffer;
ManagedBuffer allocateAligned(size_t size) {
void* buf;
int rc = posix_memalign(&buf, kAlign, size);
......@@ -128,7 +130,8 @@ ManagedBuffer allocateAligned(size_t size) {
return ManagedBuffer(reinterpret_cast<char*>(buf), free);
}
void testReadsSerially(const std::vector<TestSpec>& specs,
void testReadsSerially(
const std::vector<TestSpec>& specs,
AsyncIO::PollMode pollMode) {
AsyncIO aioReader(1, pollMode);
AsyncIO::Op op;
......@@ -155,7 +158,8 @@ void testReadsSerially(const std::vector<TestSpec>& specs,
}
}
void testReadsParallel(const std::vector<TestSpec>& specs,
void testReadsParallel(
const std::vector<TestSpec>& specs,
AsyncIO::PollMode pollMode,
bool multithreaded) {
AsyncIO aioReader(specs.size(), pollMode);
......@@ -176,7 +180,7 @@ void testReadsParallel(const std::vector<TestSpec>& specs,
for (size_t i = 0; i < specs.size(); i++) {
bufs.push_back(allocateAligned(specs[i].size));
}
auto submit = [&] (size_t i) {
auto submit = [&](size_t i) {
ops[i].pread(fd, bufs[i].get(), specs[i].size, specs[i].start);
aioReader.submit(&ops[i]);
};
......@@ -219,7 +223,8 @@ void testReadsParallel(const std::vector<TestSpec>& specs,
}
}
void testReadsQueued(const std::vector<TestSpec>& specs,
void testReadsQueued(
const std::vector<TestSpec>& specs,
AsyncIO::PollMode pollMode) {
size_t readerCapacity = std::max(specs.size() / 2, size_t(1));
AsyncIO aioReader(readerCapacity, pollMode);
......@@ -272,8 +277,7 @@ void testReadsQueued(const std::vector<TestSpec>& specs,
}
}
void testReads(const std::vector<TestSpec>& specs,
AsyncIO::PollMode pollMode) {
void testReads(const std::vector<TestSpec>& specs, AsyncIO::PollMode pollMode) {
testReadsSerially(specs, pollMode);
testReadsParallel(specs, pollMode, false);
testReadsParallel(specs, pollMode, true);
......@@ -302,46 +306,46 @@ TEST(AsyncIO, SingleAsyncDataPollable) {
TEST(AsyncIO, MultipleAsyncDataNotPollable) {
testReads(
{{kAlign, 2*kAlign}, {kAlign, 2*kAlign}, {kAlign, 4*kAlign}},
{{kAlign, 2 * kAlign}, {kAlign, 2 * kAlign}, {kAlign, 4 * kAlign}},
AsyncIO::NOT_POLLABLE);
testReads(
{{kAlign, 2*kAlign}, {kAlign, 2*kAlign}, {kAlign, 4*kAlign}},
{{kAlign, 2 * kAlign}, {kAlign, 2 * kAlign}, {kAlign, 4 * kAlign}},
AsyncIO::NOT_POLLABLE);
testReads({
{0, 5*1024*1024},
{kAlign, 5*1024*1024}
}, AsyncIO::NOT_POLLABLE);
testReads(
{{0, 5 * 1024 * 1024}, {kAlign, 5 * 1024 * 1024}}, AsyncIO::NOT_POLLABLE);
testReads({
testReads(
{
{kAlign, 0},
{kAlign, kAlign},
{kAlign, 2*kAlign},
{kAlign, 20*kAlign},
{kAlign, 1024*1024},
}, AsyncIO::NOT_POLLABLE);
{kAlign, 2 * kAlign},
{kAlign, 20 * kAlign},
{kAlign, 1024 * 1024},
},
AsyncIO::NOT_POLLABLE);
}
TEST(AsyncIO, MultipleAsyncDataPollable) {
testReads(
{{kAlign, 2*kAlign}, {kAlign, 2*kAlign}, {kAlign, 4*kAlign}},
{{kAlign, 2 * kAlign}, {kAlign, 2 * kAlign}, {kAlign, 4 * kAlign}},
AsyncIO::POLLABLE);
testReads(
{{kAlign, 2*kAlign}, {kAlign, 2*kAlign}, {kAlign, 4*kAlign}},
{{kAlign, 2 * kAlign}, {kAlign, 2 * kAlign}, {kAlign, 4 * kAlign}},
AsyncIO::POLLABLE);
testReads({
{0, 5*1024*1024},
{kAlign, 5*1024*1024}
}, AsyncIO::NOT_POLLABLE);
testReads(
{{0, 5 * 1024 * 1024}, {kAlign, 5 * 1024 * 1024}}, AsyncIO::NOT_POLLABLE);
testReads({
testReads(
{
{kAlign, 0},
{kAlign, kAlign},
{kAlign, 2*kAlign},
{kAlign, 20*kAlign},
{kAlign, 1024*1024},
}, AsyncIO::NOT_POLLABLE);
{kAlign, 2 * kAlign},
{kAlign, 20 * kAlign},
{kAlign, 1024 * 1024},
},
AsyncIO::NOT_POLLABLE);
}
TEST(AsyncIO, ManyAsyncDataNotPollable) {
......
......@@ -40,7 +40,7 @@ TEST(Simple, Path) {
EXPECT_TRUE(starts_with(abs1, root));
EXPECT_FALSE(starts_with(rel1, root));
expectPathEq(path("hello/world"), remove_prefix(abs1, root));
EXPECT_THROW({remove_prefix(rel1, root);}, filesystem_error);
EXPECT_THROW({ remove_prefix(rel1, root); }, filesystem_error);
path abs2("/hello");
path abs3("/hello/");
......@@ -55,8 +55,8 @@ TEST(Simple, Path) {
expectPathEq(path("world"), remove_prefix(abs1, abs2));
expectPathEq(path("world"), remove_prefix(abs1, abs3));
expectPathEq(path(), remove_prefix(abs1, abs4));
EXPECT_THROW({remove_prefix(abs1, abs5);}, filesystem_error);
EXPECT_THROW({remove_prefix(abs1, abs6);}, filesystem_error);
EXPECT_THROW({ remove_prefix(abs1, abs5); }, filesystem_error);
EXPECT_THROW({ remove_prefix(abs1, abs6); }, filesystem_error);
}
TEST(Simple, CanonicalizeParent) {
......@@ -69,8 +69,8 @@ TEST(Simple, CanonicalizeParent) {
expectPathEq(a, canonical_parent(b));
expectPathEq(a, canonical(b));
expectPathEq(a, canonical_parent(b));
EXPECT_THROW({canonical(c);}, filesystem_error);
EXPECT_THROW({canonical(d);}, filesystem_error);
EXPECT_THROW({ canonical(c); }, filesystem_error);
EXPECT_THROW({ canonical(d); }, filesystem_error);
expectPathEq(c, canonical_parent(c));
expectPathEq(c, canonical_parent(d));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment