Skip to content

Commit

Permalink
none
Browse files Browse the repository at this point in the history
  • Loading branch information
duzhongwei committed Apr 29, 2021
1 parent f61d57c commit d943550
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
13 changes: 4 additions & 9 deletions include/bsio/base/WaitGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,21 @@ class WaitGroup
}

template<class Rep, class Period>
void wait(const std::chrono::duration<Rep, Period>& timeout)
auto wait(const std::chrono::duration<Rep, Period>& timeout)
{
std::unique_lock<std::mutex> l(mMutex);
mCond.wait_for(l, timeout, [&] {
return mCond.wait_for(l, timeout, [&] {
return mCounter <= 0;
});
}

private:
WaitGroup()
: mCounter(0)
{
}

virtual ~WaitGroup() = default;

private:
std::mutex mMutex;
std::atomic<int> mCounter;
std::atomic<int> mCounter = {0};
std::condition_variable mCond;
};

}}// namespace bsio::base
}}// namespace bsio::base
3 changes: 1 addition & 2 deletions include/bsio/net/TcpAcceptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ class TcpAcceptor : public asio::noncopyable,

auto& ioContext = mIoContextThreadPool->pickIoContext();
auto sharedSocket = SharedSocket::Make(asio::ip::tcp::socket(ioContext), ioContext);
const auto self = shared_from_this();
mAcceptor.async_accept(
sharedSocket->socket(),
[self, callback, sharedSocket, this](std::error_code ec) mutable {
[self = shared_from_this(), this, callback, sharedSocket](std::error_code ec) mutable {
if (!ec)
{
sharedSocket->context().post([=]() {
Expand Down

0 comments on commit d943550

Please sign in to comment.