Replace WaitableEvent with portable std primitives:

The WaitableEvent class was a leftover from the pre-Boost
version of Beast and used Windows- and pthread-specific
APIs.

This refactor replaces that functionality by using only
interfaces provided by the C++ standard, making the code
more portable.

Closes #2402.
This commit is contained in:
Howard Hinnant
2018-10-22 13:51:30 -04:00
committed by Nik Bougalis
parent 5e96da51f9
commit 156e8dae83
11 changed files with 72 additions and 340 deletions

View File

@@ -32,7 +32,7 @@ Workers::Workers (
: m_callback (callback)
, perfLog_ (perfLog)
, m_threadNames (threadNames)
, m_allPaused (true, true)
, m_allPaused (true)
, m_semaphore (0)
, m_numberOfThreads (0)
, m_activeCount (0)
@@ -111,7 +111,9 @@ void Workers::pauseAllThreadsAndWait ()
{
setNumberOfThreads (0);
m_allPaused.wait ();
std::unique_lock<std::mutex> lk{m_mut};
m_cv.wait(lk, [this]{return m_allPaused;});
lk.unlock();
assert (numberOfCurrentlyRunningTasks () == 0);
}
@@ -185,7 +187,10 @@ void Workers::Worker::run ()
// we are the first one then reset the "all paused" event
//
if (++m_workers.m_activeCount == 1)
m_workers.m_allPaused.reset ();
{
std::lock_guard<std::mutex> lk{m_workers.m_mut};
m_workers.m_allPaused = false;
}
for (;;)
{
@@ -236,7 +241,11 @@ void Workers::Worker::run ()
// are the last one then signal the "all paused" event.
//
if (--m_workers.m_activeCount == 0)
m_workers.m_allPaused.signal ();
{
std::lock_guard<std::mutex> lk{m_workers.m_mut};
m_workers.m_allPaused = true;
m_workers.m_cv.notify_all();
}
// Set inactive thread name.
beast::setCurrentThreadName ("(" + threadName_ + ")");