mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
Improve locking:
- Use `std::lock` when grabbing multiple mutexes to ensure consistent locking order and avoid deadlocks. - Reduce the scope of the master mutex lock by relesing it prior to calling setHeartbeatTimer
This commit is contained in:
committed by
Manoj doshi
parent
5f908ba870
commit
595b7b194c
@@ -749,6 +749,8 @@ void NetworkOPsImp::processHeartbeatTimer ()
|
||||
<< "below required minimum (" << minPeerCount_ << ").";
|
||||
}
|
||||
|
||||
// MasterMutex lock need not be held to call setHeartbeatTimer()
|
||||
lock.unlock();
|
||||
// We do not call mConsensus.timerEntry until there are enough
|
||||
// peers providing meaningful inputs to consensus
|
||||
setHeartbeatTimer ();
|
||||
@@ -1029,11 +1031,11 @@ void NetworkOPsImp::apply (std::unique_lock<std::mutex>& batchLock)
|
||||
batchLock.unlock();
|
||||
|
||||
{
|
||||
auto lock = make_lock(app_.getMasterMutex());
|
||||
auto masterLock = make_lock(app_.getMasterMutex(), std::defer_lock);
|
||||
bool changed = false;
|
||||
{
|
||||
std::lock_guard <std::recursive_mutex> lock (
|
||||
m_ledgerMaster.peekMutex());
|
||||
auto ledgerLock = make_lock(m_ledgerMaster.peekMutex(), std::defer_lock);
|
||||
std::lock(masterLock, ledgerLock);
|
||||
|
||||
app_.openLedger().modify(
|
||||
[&](OpenView& view, beast::Journal j)
|
||||
|
||||
Reference in New Issue
Block a user