diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c9f075d5..c6bdbd739 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/muduo/base/AsyncLogging.cc b/muduo/base/AsyncLogging.cc index f899b3159..89dd13b4e 100644 --- a/muduo/base/AsyncLogging.cc +++ b/muduo/base/AsyncLogging.cc @@ -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_), @@ -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(); @@ -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); } } @@ -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) @@ -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(); } diff --git a/muduo/base/AsyncLogging.h b/muduo/base/AsyncLogging.h index cf02cbfeb..65476f31b 100644 --- a/muduo/base/AsyncLogging.h +++ b/muduo/base/AsyncLogging.h @@ -6,13 +6,9 @@ #include #include #include - #include -#include #include -#include -#include namespace muduo { @@ -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 Buffer; - typedef boost::ptr_vector BufferVector; - typedef BufferVector::auto_type BufferPtr; + typedef std::unique_ptr BufferPtr; + typedef std::vector BufferVector; const int flushInterval_; bool running_;