Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation error on Mac #659

Open
wants to merge 2 commits into
base: mac
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,5 @@ add_subdirectory(muduo/net)

if(NOT CMAKE_BUILD_NO_EXAMPLES)
add_subdirectory(examples)
else()
if(CARES_INCLUDE_DIR AND CARES_LIBRARY)
add_subdirectory(examples/cdns)
endif()
endif()

29 changes: 14 additions & 15 deletions muduo/base/AsyncLogging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ AsyncLogging::AsyncLogging(const string& basename,
running_(false),
basename_(basename),
rollSize_(rollSize),
thread_(boost::bind(&AsyncLogging::threadFunc, this), "Logging"),
thread_(std::bind(&AsyncLogging::threadFunc, this), "Logging"),
latch_(1),
mutex_(),
cond_(mutex_),
Expand All @@ -35,15 +35,12 @@ void AsyncLogging::append(const char* logline, int len)
}
else
{
buffers_.push_back(currentBuffer_.release());
buffers_.emplace_back(std::move(currentBuffer_));

if (nextBuffer_)
{
currentBuffer_ = boost::ptr_container::move(nextBuffer_);
}
else
{
currentBuffer_.reset(new Buffer); // Rarely happens
if (nextBuffer_) {
currentBuffer_ = std::move(nextBuffer_);
} else {
currentBuffer_.reset(new Buffer); // Rarely happens
}
currentBuffer_->append(logline, len);
cond_.notify();
Expand Down Expand Up @@ -73,12 +70,12 @@ void AsyncLogging::threadFunc()
{
cond_.waitForSeconds(flushInterval_);
}
buffers_.push_back(currentBuffer_.release());
currentBuffer_ = boost::ptr_container::move(newBuffer1);
buffers_.emplace_back(std::move(currentBuffer_));
currentBuffer_ = std::move(newBuffer1);
buffersToWrite.swap(buffers_);
if (!nextBuffer_)
{
nextBuffer_ = boost::ptr_container::move(newBuffer2);
nextBuffer_ = std::move(newBuffer2);
}
}

Expand All @@ -98,7 +95,7 @@ void AsyncLogging::threadFunc()
for (size_t i = 0; i < buffersToWrite.size(); ++i)
{
// FIXME: use unbuffered stdio FILE ? or use ::writev ?
output.append(buffersToWrite[i].data(), buffersToWrite[i].length());
output.append(buffersToWrite[i]->data(), buffersToWrite[i]->length());
}

if (buffersToWrite.size() > 2)
Expand All @@ -110,14 +107,16 @@ void AsyncLogging::threadFunc()
if (!newBuffer1)
{
assert(!buffersToWrite.empty());
newBuffer1 = buffersToWrite.pop_back();
newBuffer1.reset(buffersToWrite.back().release());
buffersToWrite.pop_back();
newBuffer1->reset();
}

if (!newBuffer2)
{
assert(!buffersToWrite.empty());
newBuffer2 = buffersToWrite.pop_back();
newBuffer2.reset(buffersToWrite.back().release());
buffersToWrite.pop_back();
newBuffer2->reset();
}

Expand Down
12 changes: 4 additions & 8 deletions muduo/base/AsyncLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
#include <muduo/base/CountDownLatch.h>
#include <muduo/base/Mutex.h>
#include <muduo/base/Thread.h>

#include <muduo/base/LogStream.h>

#include <boost/bind.hpp>
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/ptr_container/ptr_vector.hpp>

namespace muduo
{
Expand Down Expand Up @@ -52,14 +48,14 @@ class AsyncLogging : boost::noncopyable
private:

// declare but not define, prevent compiler-synthesized functions
AsyncLogging(const AsyncLogging&); // ptr_container
void operator=(const AsyncLogging&); // ptr_container
AsyncLogging(const AsyncLogging&);
void operator=(const AsyncLogging&);

void threadFunc();

typedef muduo::detail::FixedBuffer<muduo::detail::kLargeBuffer> Buffer;
typedef boost::ptr_vector<Buffer> BufferVector;
typedef BufferVector::auto_type BufferPtr;
typedef std::unique_ptr<Buffer> BufferPtr;
typedef std::vector<BufferPtr> BufferVector;

const int flushInterval_;
bool running_;
Expand Down