Skip to content

Commit

Permalink
Review feedback: rename readlock, add and update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ximinez committed Feb 12, 2025
1 parent 925c311 commit 217bc1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/xrpld/nodestore/detail/DatabaseRotatingImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ DatabaseRotatingImp::rotateWithLock(
// This function should be the only one taking any kind of unique/write
// lock, and should only be called once at a time by its syncronous caller.

boost::upgrade_lock readLock(mutex_, boost::defer_lock);
if (!readLock.try_lock())
// The upgradable lock will NOT block shared locks, but will block other
// upgrade locks and unique/exclusive locks.
boost::upgrade_lock upgradeableLock(mutex_, boost::defer_lock);
if (!upgradeableLock.try_lock())
{
// If anything other than a unit test gets here, something has gone very
// wrong
Expand All @@ -66,7 +68,7 @@ DatabaseRotatingImp::rotateWithLock(
// boost::upgrade_mutex guarantees that only one thread can have "upgrade
// ownership" at a time, so this is 100% safe, and guaranteed to avoid
// deadlock.
boost::upgrade_to_unique_lock writeLock(readLock);
boost::upgrade_to_unique_lock writeLock(upgradeableLock);

archiveBackend_->setDeletePath();
archiveBackend_ = std::move(writableBackend_);
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/nodestore/detail/DatabaseRotatingImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DatabaseRotatingImp : public DatabaseRotating
bool const unitTest_;

// Implements the "UpgradeLockable" concept
// https://www.boost.org/doc/libs/1_86_0/doc/html/thread/synchronization.html#thread.synchronization.mutex_concepts.upgrade_lockable
// https://www.boost.org/doc/libs/release/doc/html/thread/synchronization.html#thread.synchronization.mutex_concepts.upgrade_lockable
// In short: Many threads can have shared ownership. One thread can have
// upgradable ownership at the same time as others have shared ownership.
// The upgradeable ownership can be upgraded to exclusive ownership,
Expand Down

0 comments on commit 217bc1d

Please sign in to comment.