summaryrefslogtreecommitdiff
path: root/src/mongo/util/background.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/util/background.cpp')
-rw-r--r--src/mongo/util/background.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/mongo/util/background.cpp b/src/mongo/util/background.cpp
index e5b40238230..7f34141dfad 100644
--- a/src/mongo/util/background.cpp
+++ b/src/mongo/util/background.cpp
@@ -36,8 +36,8 @@
#include <functional>
#include "mongo/config.h"
-#include "mongo/stdx/condition_variable.h"
-#include "mongo/stdx/mutex.h"
+#include "mongo/platform/condition_variable.h"
+#include "mongo/platform/mutex.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/concurrency/mutex.h"
@@ -80,7 +80,7 @@ private:
void _runTask(PeriodicTask* task);
// _mutex protects the _shutdownRequested flag and the _tasks vector.
- stdx::mutex _mutex;
+ Mutex _mutex = MONGO_MAKE_LATCH("PeriodicTaskRunner::_mutex");
// The condition variable is used to sleep for the interval between task
// executions, and is notified when the _shutdownRequested flag is toggled.
@@ -129,7 +129,7 @@ bool runnerDestroyed = false;
struct BackgroundJob::JobStatus {
JobStatus() : state(NotStarted) {}
- stdx::mutex mutex;
+ Mutex mutex = MONGO_MAKE_LATCH("JobStatus::mutex");
stdx::condition_variable done;
State state;
};
@@ -154,7 +154,7 @@ void BackgroundJob::jobBody() {
{
// It is illegal to access any state owned by this BackgroundJob after leaving this
// scope, with the exception of the call to 'delete this' below.
- stdx::unique_lock<stdx::mutex> l(_status->mutex);
+ stdx::unique_lock<Latch> l(_status->mutex);
_status->state = Done;
_status->done.notify_all();
}
@@ -164,7 +164,7 @@ void BackgroundJob::jobBody() {
}
void BackgroundJob::go() {
- stdx::unique_lock<stdx::mutex> l(_status->mutex);
+ stdx::unique_lock<Latch> l(_status->mutex);
massert(17234,
str::stream() << "backgroundJob already running: " << name(),
_status->state != Running);
@@ -178,7 +178,7 @@ void BackgroundJob::go() {
}
Status BackgroundJob::cancel() {
- stdx::unique_lock<stdx::mutex> l(_status->mutex);
+ stdx::unique_lock<Latch> l(_status->mutex);
if (_status->state == Running)
return Status(ErrorCodes::IllegalOperation, "Cannot cancel a running BackgroundJob");
@@ -194,7 +194,7 @@ Status BackgroundJob::cancel() {
bool BackgroundJob::wait(unsigned msTimeOut) {
verify(!_selfDelete); // you cannot call wait on a self-deleting job
const auto deadline = Date_t::now() + Milliseconds(msTimeOut);
- stdx::unique_lock<stdx::mutex> l(_status->mutex);
+ stdx::unique_lock<Latch> l(_status->mutex);
while (_status->state != Done) {
if (msTimeOut) {
if (stdx::cv_status::timeout ==
@@ -208,12 +208,12 @@ bool BackgroundJob::wait(unsigned msTimeOut) {
}
BackgroundJob::State BackgroundJob::getState() const {
- stdx::unique_lock<stdx::mutex> l(_status->mutex);
+ stdx::unique_lock<Latch> l(_status->mutex);
return _status->state;
}
bool BackgroundJob::running() const {
- stdx::unique_lock<stdx::mutex> l(_status->mutex);
+ stdx::unique_lock<Latch> l(_status->mutex);
return _status->state == Running;
}
@@ -268,12 +268,12 @@ Status PeriodicTask::stopRunningPeriodicTasks(int gracePeriodMillis) {
}
void PeriodicTaskRunner::add(PeriodicTask* task) {
- stdx::lock_guard<stdx::mutex> lock(_mutex);
+ stdx::lock_guard<Latch> lock(_mutex);
_tasks.push_back(task);
}
void PeriodicTaskRunner::remove(PeriodicTask* task) {
- stdx::lock_guard<stdx::mutex> lock(_mutex);
+ stdx::lock_guard<Latch> lock(_mutex);
for (size_t i = 0; i != _tasks.size(); i++) {
if (_tasks[i] == task) {
_tasks[i] = nullptr;
@@ -284,7 +284,7 @@ void PeriodicTaskRunner::remove(PeriodicTask* task) {
Status PeriodicTaskRunner::stop(int gracePeriodMillis) {
{
- stdx::lock_guard<stdx::mutex> lock(_mutex);
+ stdx::lock_guard<Latch> lock(_mutex);
_shutdownRequested = true;
_cond.notify_one();
}
@@ -300,7 +300,7 @@ void PeriodicTaskRunner::run() {
// Use a shorter cycle time in debug mode to help catch race conditions.
const Seconds waitTime(kDebugBuild ? 5 : 60);
- stdx::unique_lock<stdx::mutex> lock(_mutex);
+ stdx::unique_lock<Latch> lock(_mutex);
while (!_shutdownRequested) {
{
MONGO_IDLE_THREAD_BLOCK;