Skip to content

Commit

Permalink
update AsyncLogWriter::performIO() to take the vector by reference
Browse files Browse the repository at this point in the history
Summary:
Update the `AsyncLogWriter::performIO()` API to take the vector of messages by
const reference, rather than by modifiable pointer.  This parameter is purely
an input parameter, and shouldn't be modified by the `performIO()` code, so it
makes more sense to take this as const reference.

Differential Revision: D21367425

fbshipit-source-id: 4bbf3a58dd48bb620101ec3982b189bea656b301
  • Loading branch information
simpkins authored and facebook-github-bot committed May 7, 2020
1 parent 439c7b2 commit f121101
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions folly/logging/AsyncFileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ bool AsyncFileWriter::ttyOutput() const {
}

void AsyncFileWriter::writeToFile(
std::vector<std::string>* ioQueue,
const std::vector<std::string>& ioQueue,
size_t numDiscarded) {
// kNumIovecs controls the maximum number of strings we write at once in a
// single writev() call.
constexpr int kNumIovecs = 64;
std::array<iovec, kNumIovecs> iovecs;

size_t idx = 0;
while (idx < ioQueue->size()) {
while (idx < ioQueue.size()) {
int numIovecs = 0;
while (numIovecs < kNumIovecs && idx < ioQueue->size()) {
const auto& str = (*ioQueue)[idx];
while (numIovecs < kNumIovecs && idx < ioQueue.size()) {
const auto& str = ioQueue[idx];
iovecs[numIovecs].iov_base = const_cast<char*>(str.data());
iovecs[numIovecs].iov_len = str.size();
++numIovecs;
Expand All @@ -70,7 +70,7 @@ void AsyncFileWriter::writeToFile(
}

void AsyncFileWriter::performIO(
std::vector<std::string>* ioQueue,
const std::vector<std::string>& ioQueue,
size_t numDiscarded) {
try {
writeToFile(ioQueue, numDiscarded);
Expand Down
6 changes: 4 additions & 2 deletions folly/logging/AsyncFileWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class AsyncFileWriter : public AsyncLogWriter {
}

private:
void writeToFile(std::vector<std::string>* ioQueue, size_t numDiscarded);
void writeToFile(
const std::vector<std::string>& ioQueue,
size_t numDiscarded);

void performIO(std::vector<std::string>* ioQueue, size_t numDiscarded)
void performIO(const std::vector<std::string>& ioQueue, size_t numDiscarded)
override;

std::string getNumDiscardedMsg(size_t numDiscarded);
Expand Down
4 changes: 2 additions & 2 deletions folly/logging/AsyncLogWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void AsyncLogWriter::cleanup() {

// If there are still any pending messages, flush them now.
if (!ioQueue->empty()) {
performIO(ioQueue, numDiscarded);
performIO(*ioQueue, numDiscarded);
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ void AsyncLogWriter::ioThread() {
ioCV_.notify_all();

// Write the log messages now that we have released the lock
performIO(ioQueue, numDiscarded);
performIO(*ioQueue, numDiscarded);

// clear() empties the vector, but the allocated capacity remains so we can
// just reuse it without having to re-allocate in most cases.
Expand Down
2 changes: 1 addition & 1 deletion folly/logging/AsyncLogWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class AsyncLogWriter : public LogWriter {
* messages. This method will be called in a separate IO thread.
*/
virtual void performIO(
std::vector<std::string>* logs,
const std::vector<std::string>& logs,
size_t numDiscarded) = 0;

void ioThread();
Expand Down
2 changes: 1 addition & 1 deletion folly/logging/test/AsyncLogWriterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void handleLoggingError(
}

class NoCleanUpLogWriter : public AsyncLogWriter {
void performIO(std::vector<std::string>*, size_t) override {}
void performIO(const std::vector<std::string>&, size_t) override {}

bool ttyOutput() const override {
return false;
Expand Down

0 comments on commit f121101

Please sign in to comment.