Skip to content

Commit 5d7470a

Browse files
PastaPastaPastaknst
authored andcommitted
Merge dashpay#6722: fix: missing mutex for bls::operator==
a488c8d fix: add missing mutex to operator== for bls wrapper (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented Somehow, CBLSLazyWrapper works correctly till now and does not cause any failures even `CBLSLazyWrapper::operator==()` doesn't have mutex inside. Let's fix it! ## What was done? Added mutex to operator== for CBLSWrapper; added ptrs comparision to operator== in case of compare `A==A` to avoid deadlock. ## How Has This Been Tested? Run unit / functional tests. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone ACKs for top commit: UdjinM6: utACK a488c8d Tree-SHA512: cef814a451d12b1ee2b548ddfe4c147690f1704dd5068821fae8d617ff2013c76862be6dae763a78abd233465b23f164af7631ebe39c72b067a853f4ee19f663
1 parent 4b5891f commit 5d7470a

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/bls/bls.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -509,19 +509,23 @@ class CBLSLazyWrapper
509509

510510
bool operator==(const CBLSLazyWrapper& r) const
511511
{
512-
// If neither bufValid or objInitialized are set, then the object is the default object.
513-
const bool is_default{!bufValid && !objInitialized};
514-
const bool r_is_default{!r.bufValid && !r.objInitialized};
515-
// If both are default; they are equal.
516-
if (is_default && r_is_default) return true;
517-
// If one is default and the other isn't, we are not equal
518-
if (is_default != r_is_default) return false;
519-
520-
if (bufValid && r.bufValid && bufLegacyScheme == r.bufLegacyScheme) {
521-
return vecBytes == r.vecBytes;
522-
}
523-
if (objInitialized && r.objInitialized) {
524-
return obj == r.obj;
512+
if (&r == this) return true;
513+
{
514+
std::scoped_lock lock(mutex, r.mutex);
515+
// If neither bufValid or objInitialized are set, then the object is the default object.
516+
const bool is_default{!bufValid && !objInitialized};
517+
const bool r_is_default{!r.bufValid && !r.objInitialized};
518+
// If both are default; they are equal.
519+
if (is_default && r_is_default) return true;
520+
// If one is default and the other isn't, we are not equal
521+
if (is_default != r_is_default) return false;
522+
523+
if (bufValid && r.bufValid && bufLegacyScheme == r.bufLegacyScheme) {
524+
return vecBytes == r.vecBytes;
525+
}
526+
if (objInitialized && r.objInitialized) {
527+
return obj == r.obj;
528+
}
525529
}
526530
return Get() == r.Get();
527531
}

0 commit comments

Comments
 (0)