Skip to content

Commit

Permalink
Replace boost locks and mutexes with std-equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeLoser authored and nbougalis committed Jul 17, 2018
1 parent e222ff5 commit 79d8195
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/ripple/app/misc/ValidatorList.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
#include <ripple/protocol/PublicKey.h>
#include <boost/iterator/counting_iterator.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <mutex>
#include <shared_mutex>
#include <numeric>

namespace ripple {
Expand Down Expand Up @@ -129,7 +128,7 @@ class ValidatorList
ManifestCache& publisherManifests_;
TimeKeeper& timeKeeper_;
beast::Journal j_;
boost::shared_mutex mutable mutex_;
std::shared_timed_mutex mutable mutex_;

std::atomic<std::size_t> quorum_;
boost::optional<std::size_t> minimumQuorum_;
Expand Down
27 changes: 15 additions & 12 deletions src/ripple/app/misc/impl/ValidatorList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include <boost/beast/core/detail/base64.hpp>
#include <boost/regex.hpp>

#include <mutex>
#include <shared_mutex>

namespace ripple {

std::string
Expand Down Expand Up @@ -82,7 +85,7 @@ ValidatorList::load (
")?" // end optional comment block
);

boost::unique_lock<boost::shared_mutex> read_lock{mutex_};
std::unique_lock<std::shared_timed_mutex> read_lock{mutex_};

JLOG (j_.debug()) <<
"Loading configured trusted validator list publisher keys";
Expand Down Expand Up @@ -198,7 +201,7 @@ ValidatorList::applyList (
if (version != requiredListVersion)
return ListDisposition::unsupported_version;

boost::unique_lock<boost::shared_mutex> lock{mutex_};
std::unique_lock<std::shared_timed_mutex> lock{mutex_};

Json::Value list;
PublicKey pubKey;
Expand Down Expand Up @@ -376,7 +379,7 @@ bool
ValidatorList::listed (
PublicKey const& identity) const
{
boost::shared_lock<boost::shared_mutex> read_lock{mutex_};
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};

auto const pubKey = validatorManifests_.getMasterKey (identity);
return keyListings_.find (pubKey) != keyListings_.end ();
Expand All @@ -385,7 +388,7 @@ ValidatorList::listed (
bool
ValidatorList::trusted (PublicKey const& identity) const
{
boost::shared_lock<boost::shared_mutex> read_lock{mutex_};
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};

auto const pubKey = validatorManifests_.getMasterKey (identity);
return trustedKeys_.find (pubKey) != trustedKeys_.end();
Expand All @@ -395,7 +398,7 @@ boost::optional<PublicKey>
ValidatorList::getListedKey (
PublicKey const& identity) const
{
boost::shared_lock<boost::shared_mutex> read_lock{mutex_};
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};

auto const pubKey = validatorManifests_.getMasterKey (identity);
if (keyListings_.find (pubKey) != keyListings_.end ())
Expand All @@ -406,7 +409,7 @@ ValidatorList::getListedKey (
boost::optional<PublicKey>
ValidatorList::getTrustedKey (PublicKey const& identity) const
{
boost::shared_lock<boost::shared_mutex> read_lock{mutex_};
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};

auto const pubKey = validatorManifests_.getMasterKey (identity);
if (trustedKeys_.find (pubKey) != trustedKeys_.end())
Expand All @@ -417,14 +420,14 @@ ValidatorList::getTrustedKey (PublicKey const& identity) const
bool
ValidatorList::trustedPublisher (PublicKey const& identity) const
{
boost::shared_lock<boost::shared_mutex> read_lock{mutex_};
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
return identity.size() && publisherLists_.count (identity);
}

PublicKey
ValidatorList::localPublicKey () const
{
boost::shared_lock<boost::shared_mutex> read_lock{mutex_};
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
return localPubKey_;
}

Expand Down Expand Up @@ -459,7 +462,7 @@ ValidatorList::removePublisherList (PublicKey const& publisherKey)
boost::optional<TimeKeeper::time_point>
ValidatorList::expires() const
{
boost::shared_lock<boost::shared_mutex> read_lock{mutex_};
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};
boost::optional<TimeKeeper::time_point> res{boost::none};
for (auto const& p : publisherLists_)
{
Expand All @@ -479,7 +482,7 @@ ValidatorList::getJson() const
{
Json::Value res(Json::objectValue);

boost::shared_lock<boost::shared_mutex> read_lock{mutex_};
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};

res[jss::validation_quorum] = static_cast<Json::UInt>(quorum());

Expand Down Expand Up @@ -561,7 +564,7 @@ void
ValidatorList::for_each_listed (
std::function<void(PublicKey const&, bool)> func) const
{
boost::shared_lock<boost::shared_mutex> read_lock{mutex_};
std::shared_lock<std::shared_timed_mutex> read_lock{mutex_};

for (auto const& v : keyListings_)
func (v.first, trusted(v.first));
Expand Down Expand Up @@ -629,7 +632,7 @@ ValidatorList::calculateQuorum (
TrustChanges
ValidatorList::updateTrusted(hash_set<NodeID> const& seenValidators)
{
boost::unique_lock<boost::shared_mutex> lock{mutex_};
std::unique_lock<std::shared_timed_mutex> lock{mutex_};

// Remove any expired published lists
for (auto const& list : publisherLists_)
Expand Down

0 comments on commit 79d8195

Please sign in to comment.