Skip to content
Merged
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
13 changes: 9 additions & 4 deletions include/brynet/base/WaitGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ class WaitGroup : public NonCopyable
public:
void add(int i = 1)
{
std::unique_lock<std::mutex> l(mMutex);
mCounter += i;
}

void done()
{
std::unique_lock<std::mutex> l(mMutex);
--mCounter;
mCond.notify_all();
if (mCounter <= 0)
{
mCond.notify_all();
}
}

void wait()
Expand All @@ -43,10 +48,10 @@ class WaitGroup : public NonCopyable
}

template<class Rep, class Period>
void wait(const std::chrono::duration<Rep, Period>& timeout)
bool 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;
});
}
Expand All @@ -61,7 +66,7 @@ class WaitGroup : public NonCopyable

private:
std::mutex mMutex;
std::atomic<int> mCounter;
int mCounter;
std::condition_variable mCond;
};
}}// namespace brynet::base
2 changes: 1 addition & 1 deletion include/brynet/net/PromiseReceive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace brynet { namespace net {

/* binary search in memory */
void memsearch(const char* hay, size_t haysize, const char* needle, size_t needlesize, size_t& result, bool& isOK)
static void memsearch(const char* hay, size_t haysize, const char* needle, size_t needlesize, size_t& result, bool& isOK)
{
size_t haypos, needlepos;
haysize -= needlesize;
Expand Down
Loading