summaryrefslogtreecommitdiff
path: root/src/mongo/db/curop.h
diff options
context:
space:
mode:
authorJustin Seyster <justin.seyster@mongodb.com>2020-08-04 16:54:02 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-04 21:14:53 +0000
commitb579403c660583fdf657ad379da235537fe2396b (patch)
tree0aa59eab1423e08687708f17659faab313cd5009 /src/mongo/db/curop.h
parentd1203723ec3de880aaee081d49396b755016fcf0 (diff)
downloadmongo-b579403c660583fdf657ad379da235537fe2396b.tar.gz
SERVER-49030 Make CurOp::_start and CurOp::_end atomic
Diffstat (limited to 'src/mongo/db/curop.h')
-rw-r--r--src/mongo/db/curop.h38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/mongo/db/curop.h b/src/mongo/db/curop.h
index 0ee19dde2bf..1309d9835a2 100644
--- a/src/mongo/db/curop.h
+++ b/src/mongo/db/curop.h
@@ -469,13 +469,13 @@ public:
// negative, if the system time has been reset during the course of this operation.
//
- void ensureStarted();
- bool isStarted() const {
- return _start > 0;
+ void ensureStarted() {
+ static_cast<void>(startTime());
}
- void done() {
- _end = _tickSource->getTicks();
+ bool isStarted() const {
+ return _start.load() != 0;
}
+ void done();
bool isDone() const {
return _end > 0;
}
@@ -571,15 +571,12 @@ public:
* If this op has not yet been started, returns 0.
*/
Microseconds elapsedTimeTotal() {
- if (!isStarted()) {
+ auto start = _start.load();
+ if (start == 0) {
return Microseconds{0};
}
- if (!_end) {
- return _tickSource->ticksTo<Microseconds>(_tickSource->getTicks() - startTime());
- } else {
- return _tickSource->ticksTo<Microseconds>(_end - startTime());
- }
+ return computeElapsedTimeTotal(start, _end.load());
}
/**
@@ -593,11 +590,13 @@ public:
*/
Microseconds elapsedTimeExcludingPauses() {
invariant(!_lastPauseTime);
- if (!isStarted()) {
+
+ auto start = _start.load();
+ if (start == 0) {
return Microseconds{0};
}
- return elapsedTimeTotal() - _totalPausedDuration;
+ return computeElapsedTimeTotal(start, _end.load()) - _totalPausedDuration;
}
/**
@@ -727,10 +726,9 @@ public:
private:
class CurOpStack;
- TickSource::Tick startTime() {
- ensureStarted();
- return _start;
- }
+ TickSource::Tick startTime();
+ Microseconds computeElapsedTimeTotal(TickSource::Tick startTime,
+ TickSource::Tick endTime) const;
static const OperationContext::Decoration<CurOpStack> _curopStack;
@@ -741,10 +739,10 @@ private:
const Command* _command{nullptr};
// The time at which this CurOp instance was marked as started.
- TickSource::Tick _start{0};
+ std::atomic<TickSource::Tick> _start{0}; // NOLINT
- // The time at which this CurOp instance was marked as done.
- TickSource::Tick _end{0};
+ // The time at which this CurOp instance was marked as done or 0 if the CurOp is not yet done.
+ std::atomic<TickSource::Tick> _end{0}; // NOLINT
// The time at which this CurOp instance had its timer paused, or 0 if the timer is not
// currently paused.