diff options
-rw-r--r-- | src/mongo/db/repl/applier.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/repl/applier.h | 8 | ||||
-rw-r--r-- | src/mongo/db/repl/applier_test.cpp | 40 |
3 files changed, 30 insertions, 33 deletions
diff --git a/src/mongo/db/repl/applier.cpp b/src/mongo/db/repl/applier.cpp index faa4150bdea..e9fe83b908c 100644 --- a/src/mongo/db/repl/applier.cpp +++ b/src/mongo/db/repl/applier.cpp @@ -30,9 +30,6 @@ #include "mongo/db/repl/applier.h" -#include <boost/thread/lock_guard.hpp> -#include <boost/thread/lock_types.hpp> - #include "mongo/db/operation_context.h" #include "mongo/db/repl/replication_executor.h" #include "mongo/util/assert_util.h" @@ -71,7 +68,7 @@ namespace repl { } std::string Applier::getDiagnosticString() const { - boost::lock_guard<boost::mutex> lk(_mutex); + stdx::lock_guard<stdx::mutex> lk(_mutex); str::stream output; output << "Applier"; output << " executor: " << _executor->getDiagnosticString(); @@ -80,12 +77,12 @@ namespace repl { } bool Applier::isActive() const { - boost::lock_guard<boost::mutex> lk(_mutex); + stdx::lock_guard<stdx::mutex> lk(_mutex); return _active; } Status Applier::start() { - boost::lock_guard<boost::mutex> lk(_mutex); + stdx::lock_guard<stdx::mutex> lk(_mutex); if (_active) { return Status(ErrorCodes::IllegalOperation, "applier already started"); @@ -106,7 +103,7 @@ namespace repl { void Applier::cancel() { ReplicationExecutor::CallbackHandle dbWorkCallbackHandle; { - boost::lock_guard<boost::mutex> lk(_mutex); + stdx::lock_guard<stdx::mutex> lk(_mutex); if (!_active) { return; @@ -121,7 +118,7 @@ namespace repl { } void Applier::wait() { - boost::unique_lock<boost::mutex> lk(_mutex); + stdx::unique_lock<stdx::mutex> lk(_mutex); while (_active) { _condition.wait(lk); @@ -164,7 +161,7 @@ namespace repl { void Applier::_finishCallback(const StatusWith<Timestamp>& result, const Operations& operations) { _onCompletion(result, operations); - boost::lock_guard<boost::mutex> lk(_mutex); + stdx::lock_guard<stdx::mutex> lk(_mutex); _active = false; _condition.notify_all(); } diff --git a/src/mongo/db/repl/applier.h b/src/mongo/db/repl/applier.h index f89714e9dc8..43ace1dfa23 100644 --- a/src/mongo/db/repl/applier.h +++ b/src/mongo/db/repl/applier.h @@ -28,8 +28,6 @@ #pragma once -#include <boost/thread/condition.hpp> -#include <boost/thread/mutex.hpp> #include <string> #include <vector> @@ -38,7 +36,9 @@ #include "mongo/base/status_with.h" #include "mongo/bson/bsonobj.h" #include "mongo/db/repl/replication_executor.h" +#include "mongo/stdx/condition_variable.h" #include "mongo/stdx/functional.h" +#include "mongo/stdx/mutex.h" namespace mongo { namespace repl { @@ -132,9 +132,9 @@ namespace repl { CallbackFn _onCompletion; // Protects member data of this Applier. - mutable boost::mutex _mutex; + mutable stdx::mutex _mutex; - boost::condition _condition; + stdx::condition_variable _condition; // _active is true when Applier is scheduled to be run by the executor. bool _active; diff --git a/src/mongo/db/repl/applier_test.cpp b/src/mongo/db/repl/applier_test.cpp index ce1f52d627d..690a785b846 100644 --- a/src/mongo/db/repl/applier_test.cpp +++ b/src/mongo/db/repl/applier_test.cpp @@ -175,7 +175,7 @@ namespace { barrier.countDownAndWait(); // generation 0 }); const BSONObj operation = BSON("ts" << Timestamp(Seconds(123), 0)); - boost::mutex mutex; + stdx::mutex mutex; StatusWith<Timestamp> result = getDetectableErrorStatus(); Applier::Operations operations; _applier.reset(new Applier( @@ -183,7 +183,7 @@ namespace { {operation}, [](OperationContext* txn, const BSONObj& operation) { return Status::OK(); }, [&](const StatusWith<Timestamp>& theResult, const Operations& theOperations) { - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); result = theResult; operations = theOperations; })); @@ -197,7 +197,7 @@ namespace { getApplier()->wait(); ASSERT_FALSE(getApplier()->isActive()); - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); ASSERT_EQUALS(ErrorCodes::CallbackCanceled, result.getStatus().code()); ASSERT_EQUALS(1U, operations.size()); ASSERT_EQUALS(operation, operations.front()); @@ -214,7 +214,7 @@ namespace { sleepmillis(1); }); const BSONObj operation = BSON("ts" << Timestamp(Seconds(123), 0)); - boost::mutex mutex; + stdx::mutex mutex; StatusWith<Timestamp> result = getDetectableErrorStatus(); Applier::Operations operations; _applier.reset(new Applier( @@ -222,7 +222,7 @@ namespace { {operation}, [](OperationContext* txn, const BSONObj& operation) { return Status::OK(); }, [&](const StatusWith<Timestamp>& theResult, const Operations& theOperations) { - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); result = theResult; operations = theOperations; })); @@ -237,7 +237,7 @@ namespace { // statuses. _applier.reset(); - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); if (result.isOK()) { ASSERT_TRUE(operations.empty()); } @@ -250,7 +250,7 @@ namespace { TEST_F(ApplierTest, WaitForCompletion) { const Timestamp timestamp(Seconds(123), 0); - boost::mutex mutex; + stdx::mutex mutex; StatusWith<Timestamp> result = getDetectableErrorStatus(); Applier::Operations operations; _applier.reset(new Applier( @@ -258,7 +258,7 @@ namespace { {BSON("ts" << timestamp)}, [](OperationContext* txn, const BSONObj& operation) { return Status::OK(); }, [&](const StatusWith<Timestamp>& theResult, const Operations& theOperations) { - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); result = theResult; operations = theOperations; })); @@ -267,7 +267,7 @@ namespace { getApplier()->wait(); ASSERT_FALSE(getApplier()->isActive()); - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(timestamp, result.getValue()); ASSERT_TRUE(operations.empty()); @@ -276,7 +276,7 @@ namespace { TEST_F(ApplierTest, DestroyShouldBlockUntilInactive) { const Timestamp timestamp(Seconds(123), 0); unittest::Barrier barrier(2U); - boost::mutex mutex; + stdx::mutex mutex; StatusWith<Timestamp> result = getDetectableErrorStatus(); Applier::Operations operations; _applier.reset(new Applier( @@ -284,7 +284,7 @@ namespace { {BSON("ts" << timestamp)}, [](OperationContext* txn, const BSONObj& operation) { return Status::OK(); }, [&](const StatusWith<Timestamp>& theResult, const Operations& theOperations) { - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); result = theResult; operations = theOperations; barrier.countDownAndWait(); @@ -294,7 +294,7 @@ namespace { barrier.countDownAndWait(); _applier.reset(); - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(timestamp, result.getValue()); ASSERT_TRUE(operations.empty()); @@ -307,14 +307,14 @@ namespace { BSON("op" << "b" << "ts" << Timestamp(Seconds(456), 0)), BSON("op" << "c" << "ts" << Timestamp(Seconds(789), 0)), }; - boost::mutex mutex; + stdx::mutex mutex; StatusWith<Timestamp> result = getDetectableErrorStatus(); bool areWritesReplicationOnOperationContext = true; bool isLockBatchWriter = false; Applier::Operations operationsApplied; Applier::Operations operationsOnCompletion; auto apply = [&](OperationContext* txn, const BSONObj& operation) { - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); areWritesReplicationOnOperationContext = txn->writesAreReplicated(); isLockBatchWriter = txn->lockState()->isBatchWriter(); operationsApplied.push_back(operation); @@ -322,7 +322,7 @@ namespace { }; auto callback = [&](const StatusWith<Timestamp>& theResult, const Operations& theOperations) { - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); result = theResult; operationsOnCompletion = theOperations; }; @@ -331,7 +331,7 @@ namespace { _applier->start(); _applier->wait(); - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); ASSERT_FALSE(areWritesReplicationOnOperationContext); ASSERT_TRUE(isLockBatchWriter); ASSERT_EQUALS(operationsToApply.size(), operationsApplied.size()); @@ -350,12 +350,12 @@ namespace { BSON("op" << "b" << "ts" << Timestamp(Seconds(456), 0)), BSON("op" << "c" << "ts" << Timestamp(Seconds(789), 0)), }; - boost::mutex mutex; + stdx::mutex mutex; StatusWith<Timestamp> result = getDetectableErrorStatus(); Applier::Operations operationsApplied; Applier::Operations operationsOnCompletion; auto apply = [&](OperationContext* txn, const BSONObj& operation) { - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); if (operationsApplied.size() == opIndex) { return fail(); } @@ -364,7 +364,7 @@ namespace { }; auto callback = [&](const StatusWith<Timestamp>& theResult, const Operations& theOperations) { - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); result = theResult; operationsOnCompletion = theOperations; }; @@ -373,7 +373,7 @@ namespace { _applier->start(); _applier->wait(); - boost::lock_guard<boost::mutex> lock(mutex); + stdx::lock_guard<stdx::mutex> lock(mutex); ASSERT_EQUALS(opIndex, operationsApplied.size()); size_t i = 0; for (const auto& operation : operationsApplied) { |