mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 02:25:52 +00:00
Fix destructor race in Job
This commit is contained in:
@@ -180,7 +180,7 @@ private:
|
||||
//
|
||||
// Invariants:
|
||||
// <none>
|
||||
void finishJob (Job const& job);
|
||||
void finishJob (JobType type);
|
||||
|
||||
template <class Rep, class Period>
|
||||
void on_dequeue (JobType type,
|
||||
|
||||
@@ -80,6 +80,10 @@ void Job::doJob ()
|
||||
m_loadEvent->reName (mName);
|
||||
|
||||
mJob (*this);
|
||||
|
||||
// Destroy the lambda, otherwise we won't include
|
||||
// its duration in the time measurement
|
||||
mJob = std::function<void(Job&)>();
|
||||
}
|
||||
|
||||
void Job::rename (std::string const& newName)
|
||||
|
||||
@@ -407,14 +407,11 @@ JobQueue::getNextJob (Job& job)
|
||||
}
|
||||
|
||||
void
|
||||
JobQueue::finishJob (Job const& job)
|
||||
JobQueue::finishJob (JobType type)
|
||||
{
|
||||
JobType const type = job.getType ();
|
||||
|
||||
assert (m_jobSet.find (job) == m_jobSet.end ());
|
||||
assert(type != jtINVALID);
|
||||
|
||||
JobTypeData& data (getJobTypeData (type));
|
||||
JobTypeData& data = getJobTypeData (type);
|
||||
|
||||
// Queue a deferred task if possible
|
||||
if (data.deferred > 0)
|
||||
@@ -456,6 +453,9 @@ void JobQueue::on_execute (JobType type,
|
||||
|
||||
void
|
||||
JobQueue::processTask ()
|
||||
{
|
||||
JobType type;
|
||||
|
||||
{
|
||||
Job job;
|
||||
|
||||
@@ -487,10 +487,16 @@ JobQueue::processTask ()
|
||||
JLOG(m_journal.trace) << "Skipping processTask ('" << data.name () << "')";
|
||||
}
|
||||
|
||||
type = job.getType();
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard <std::mutex> lock (m_mutex);
|
||||
finishJob (job);
|
||||
finishJob (type);
|
||||
--m_processCount;
|
||||
// Job should be destroyed before calling checkStopped
|
||||
// otherwise destructors with side effects can access
|
||||
// parent objects that are already destroyed.
|
||||
checkStopped (lock);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user