mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add JobQueue::rendezvous
This commit is contained in:
@@ -28,8 +28,9 @@
|
||||
#include <beast/threads/Stoppable.h>
|
||||
#include <beast/module/core/thread/Workers.h>
|
||||
#include <boost/function.hpp>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <set>
|
||||
#include <thread>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -95,6 +96,10 @@ public:
|
||||
// Cannot be const because LoadMonitor has no const methods.
|
||||
Json::Value getJson (int c = 0);
|
||||
|
||||
/** Block until no tasks running. */
|
||||
void
|
||||
rendezvous();
|
||||
|
||||
private:
|
||||
using JobDataMap = std::map <JobType, JobTypeData>;
|
||||
|
||||
@@ -116,6 +121,8 @@ private:
|
||||
beast::insight::Gauge job_count;
|
||||
beast::insight::Hook hook;
|
||||
|
||||
std::condition_variable cv_;
|
||||
|
||||
static JobTypes const& getJobTypes()
|
||||
{
|
||||
static JobTypes types;
|
||||
|
||||
@@ -305,6 +305,17 @@ JobQueue::getJson (int c)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
JobQueue::rendezvous()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
cv_.wait(lock, [&]
|
||||
{
|
||||
return m_processCount == 0 &&
|
||||
m_jobSet.empty();
|
||||
});
|
||||
}
|
||||
|
||||
JobTypeData&
|
||||
JobQueue::getJobTypeData (JobType type)
|
||||
{
|
||||
@@ -476,11 +487,12 @@ JobQueue::processTask ()
|
||||
|
||||
{
|
||||
std::lock_guard <std::mutex> lock (m_mutex);
|
||||
finishJob (type);
|
||||
--m_processCount;
|
||||
// Job should be destroyed before calling checkStopped
|
||||
// otherwise destructors with side effects can access
|
||||
// parent objects that are already destroyed.
|
||||
finishJob (type);
|
||||
if(--m_processCount == 0 && m_jobSet.empty())
|
||||
cv_.notify_all();
|
||||
checkStopped (lock);
|
||||
}
|
||||
|
||||
|
||||
@@ -184,6 +184,9 @@ Env::AppBundle::AppBundle(beast::unit_test::suite& suite,
|
||||
Env::AppBundle::~AppBundle()
|
||||
{
|
||||
client.reset();
|
||||
// Make sure all jobs finish, otherwise tests
|
||||
// might not get the coverage they expect.
|
||||
app->getJobQueue().rendezvous();
|
||||
app->signalStop();
|
||||
thread.join();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user