summaryrefslogtreecommitdiff
path: root/src/mongo/util
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2020-05-15 12:26:39 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-15 16:50:45 +0000
commit81acea044bd20afdf628bd29f9d5d7666057da4a (patch)
tree239a37d865db618888f39d3f97b0c64ac49b207f /src/mongo/util
parent2dc2b30e10f20a7d75faff0f35d3696660fd8721 (diff)
downloadmongo-81acea044bd20afdf628bd29f9d5d7666057da4a.tar.gz
SERVER-48171 consolidate implementations for FailPoint waiting functions
Diffstat (limited to 'src/mongo/util')
-rw-r--r--src/mongo/util/fail_point.cpp14
-rw-r--r--src/mongo/util/fail_point.h7
2 files changed, 7 insertions, 14 deletions
diff --git a/src/mongo/util/fail_point.cpp b/src/mongo/util/fail_point.cpp
index 84a1029bc38..c0a28ddb3ac 100644
--- a/src/mongo/util/fail_point.cpp
+++ b/src/mongo/util/fail_point.cpp
@@ -108,20 +108,16 @@ auto FailPoint::setMode(Mode mode, ValType val, BSONObj extra) -> EntryCountT {
}
auto FailPoint::waitForTimesEntered(EntryCountT targetTimesEntered) const noexcept -> EntryCountT {
- auto timesEntered = _timesEntered.load();
- for (; timesEntered < targetTimesEntered; timesEntered = _timesEntered.load()) {
- sleepmillis(duration_cast<Milliseconds>(kWaitGranularity).count());
- };
- return timesEntered;
+ return waitForTimesEntered(Interruptible::notInterruptible(), targetTimesEntered);
}
auto FailPoint::waitForTimesEntered(Interruptible* interruptible,
EntryCountT targetTimesEntered) const -> EntryCountT {
- auto timesEntered = _timesEntered.load();
- for (; timesEntered < targetTimesEntered; timesEntered = _timesEntered.load()) {
+ while (true) {
+ if (auto entries = _timesEntered.load(); entries >= targetTimesEntered)
+ return entries;
interruptible->sleepFor(kWaitGranularity);
- };
- return timesEntered;
+ }
}
const BSONObj& FailPoint::_getData() const {
diff --git a/src/mongo/util/fail_point.h b/src/mongo/util/fail_point.h
index 7467ce4d67a..5322fad8b67 100644
--- a/src/mongo/util/fail_point.h
+++ b/src/mongo/util/fail_point.h
@@ -326,15 +326,12 @@ public:
}
/**
- * Take 100msec pauses for as long as the FailPoint is active.
+ * Take 'kWaitGranularity' pauses for as long as the FailPoint is active.
* This calls `shouldFail()` with kFirstTimeEntered once and with kEnteredAlready thereafter, so
* affects FailPoint counters once.
*/
void pauseWhileSet() {
- for (auto entryMode = kFirstTimeEntered; MONGO_unlikely(shouldFail(entryMode));
- entryMode = kEnteredAlready) {
- sleepmillis(100);
- }
+ pauseWhileSet(Interruptible::notInterruptible());
}
/**