summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/commands/mr.cpp4
-rw-r--r--src/mongo/db/commands/mr.h3
-rw-r--r--src/mongo/db/concurrency/lock_mgr.h19
-rw-r--r--src/mongo/db/curop.cpp6
-rw-r--r--src/mongo/db/curop.h8
-rw-r--r--src/mongo/db/global_environment_d.cpp9
-rw-r--r--src/mongo/db/global_environment_d.h2
-rw-r--r--src/mongo/db/global_environment_experiment.h3
-rw-r--r--src/mongo/db/global_environment_noop.cpp2
-rw-r--r--src/mongo/db/global_environment_noop.h2
-rw-r--r--src/mongo/db/index_builder.cpp4
-rw-r--r--src/mongo/db/index_builder.h3
-rw-r--r--src/mongo/db/instance.cpp2
-rw-r--r--src/mongo/db/operation_context_impl.cpp4
-rw-r--r--src/mongo/db/repl/rs_config.cpp6
-rw-r--r--src/mongo/db/sorter/sorter.cpp6
-rw-r--r--src/mongo/db/stats/counters.cpp50
-rw-r--r--src/mongo/db/stats/counters.h27
18 files changed, 82 insertions, 78 deletions
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 6f697087659..dd9feb4a351 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -64,7 +64,7 @@ namespace mongo {
namespace mr {
- AtomicUInt Config::JOB_NUMBER;
+ AtomicUInt32 Config::JOB_NUMBER;
JSFunction::JSFunction( const std::string& type , const BSONElement& e ) {
_type = type;
@@ -276,7 +276,7 @@ namespace mongo {
<< ".tmp.mr."
<< cmdObj.firstElement().String()
<< "_"
- << JOB_NUMBER++;
+ << JOB_NUMBER.fetchAndAdd(1);
incLong = tempNamespace + "_inc";
}
diff --git a/src/mongo/db/commands/mr.h b/src/mongo/db/commands/mr.h
index 06e1bcb66f4..500e677428c 100644
--- a/src/mongo/db/commands/mr.h
+++ b/src/mongo/db/commands/mr.h
@@ -38,6 +38,7 @@
#include "mongo/db/curop.h"
#include "mongo/db/instance.h"
#include "mongo/db/jsobj.h"
+#include "mongo/platform/atomic_word.h"
#include "mongo/scripting/engine.h"
namespace mongo {
@@ -227,7 +228,7 @@ namespace mongo {
// true when called from mongos to do phase-1 of M/R
bool shardedFirstPass;
- static AtomicUInt JOB_NUMBER;
+ static AtomicUInt32 JOB_NUMBER;
}; // end MRsetup
/**
diff --git a/src/mongo/db/concurrency/lock_mgr.h b/src/mongo/db/concurrency/lock_mgr.h
index 9a94bd33799..a38b4f3aec7 100644
--- a/src/mongo/db/concurrency/lock_mgr.h
+++ b/src/mongo/db/concurrency/lock_mgr.h
@@ -36,10 +36,11 @@
#include <string>
#include <vector>
+#include "mongo/platform/atomic_word.h"
#include "mongo/platform/compiler.h"
#include "mongo/platform/cstdint.h"
#include "mongo/util/timer.h"
-#include "mongo/bson/util/atomic_int.h"
+
/*
* LockManager controls access to resources through two functions: acquire and release
@@ -620,14 +621,18 @@ namespace mongo {
// support functions for changing policy to/from read/write only
void _incStatsForMode(const LockMode& mode) {
- kShared==mode ? _numCurrentActiveReadRequests++ : _numCurrentActiveWriteRequests++;
+ kShared==mode ?
+ _numCurrentActiveReadRequests.fetchAndAdd(1) :
+ _numCurrentActiveWriteRequests.fetchAndAdd(1);
}
void _decStatsForMode(const LockMode& mode) {
- kShared==mode ? _numCurrentActiveReadRequests-- : _numCurrentActiveWriteRequests--;
+ kShared==mode ?
+ _numCurrentActiveReadRequests.fetchAndSubtract(1) :
+ _numCurrentActiveWriteRequests.fetchAndSubtract(1);
}
- unsigned _numActiveReads() const { return _numCurrentActiveReadRequests; }
- unsigned _numActiveWrites() const { return _numCurrentActiveWriteRequests; }
+ unsigned _numActiveReads() const { return _numCurrentActiveReadRequests.loadRelaxed(); }
+ unsigned _numActiveWrites() const { return _numCurrentActiveWriteRequests.loadRelaxed(); }
private:
@@ -685,8 +690,8 @@ namespace mongo {
LockStats _stats[kNumResourcePartitions];
// used when changing policy to/from Readers/Writers Only
- AtomicUInt _numCurrentActiveReadRequests;
- AtomicUInt _numCurrentActiveWriteRequests;
+ AtomicUInt32 _numCurrentActiveReadRequests;
+ AtomicUInt32 _numCurrentActiveWriteRequests;
};
/**
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp
index d4855becf24..48e644b1f1c 100644
--- a/src/mongo/db/curop.cpp
+++ b/src/mongo/db/curop.cpp
@@ -62,7 +62,7 @@ namespace mongo {
_active = false;
_reset();
_op = 0;
- _opNum = _nextOpNum++;
+ _opNum = _nextOpNum.fetchAndAdd(1);
_command = NULL;
}
@@ -84,7 +84,7 @@ namespace mongo {
void CurOp::reset() {
_reset();
_start = 0;
- _opNum = _nextOpNum++;
+ _opNum = _nextOpNum.fetchAndAdd(1);
_debug.reset();
_query.reset();
_active = true; // this should be last for ui clarity
@@ -258,7 +258,7 @@ namespace mongo {
return _maxTimeTracker.getRemainingMicros();
}
- AtomicUInt CurOp::_nextOpNum;
+ AtomicUInt32 CurOp::_nextOpNum;
static Counter64 returnedCounter;
static Counter64 insertedCounter;
diff --git a/src/mongo/db/curop.h b/src/mongo/db/curop.h
index e895799abba..ed8b9057ae8 100644
--- a/src/mongo/db/curop.h
+++ b/src/mongo/db/curop.h
@@ -31,8 +31,8 @@
#pragma once
-#include "mongo/bson/util/atomic_int.h"
#include "mongo/db/client.h"
+#include "mongo/platform/atomic_word.h"
#include "mongo/util/concurrency/spin_lock.h"
#include "mongo/util/net/hostandport.h"
#include "mongo/util/progress_meter.h"
@@ -212,7 +212,7 @@ namespace mongo {
return _dbprofile >= 2 || ms >= serverGlobalParams.slowMS;
}
- AtomicUInt opNum() const { return _opNum; }
+ unsigned int opNum() const { return _opNum; }
/** if this op is running */
bool active() const { return _active; }
@@ -325,7 +325,7 @@ namespace mongo {
friend class Client;
void _reset();
- static AtomicUInt _nextOpNum;
+ static AtomicUInt32 _nextOpNum;
Client * _client;
CurOp * _wrapped;
Command * _command;
@@ -336,7 +336,7 @@ namespace mongo {
int _op;
bool _isCommand;
int _dbprofile; // 0=off, 1=slow, 2=all
- AtomicUInt _opNum; // todo: simple being "unsigned" may make more sense here
+ unsigned int _opNum;
ThreadSafeString _ns;
HostAndPort _remote; // CAREFUL here with thread safety
CachedBSONObj<512> _query; // CachedBSONObj is thread safe
diff --git a/src/mongo/db/global_environment_d.cpp b/src/mongo/db/global_environment_d.cpp
index f7eeb67aa3b..27155f89c3d 100644
--- a/src/mongo/db/global_environment_d.cpp
+++ b/src/mongo/db/global_environment_d.cpp
@@ -30,7 +30,6 @@
#include <set>
-#include "mongo/bson/util/atomic_int.h"
#include "mongo/db/client.h"
#include "mongo/db/curop.h"
#include "mongo/db/operation_context_impl.h"
@@ -56,7 +55,7 @@ namespace mongo {
}
namespace {
- void interruptJs(AtomicUInt* op) {
+ void interruptJs(unsigned int op) {
if (!globalScriptEngine) {
return;
}
@@ -65,7 +64,7 @@ namespace mongo {
globalScriptEngine->interruptAll();
}
else {
- globalScriptEngine->interrupt(*op);
+ globalScriptEngine->interrupt(op);
}
}
} // namespace
@@ -79,7 +78,7 @@ namespace mongo {
return _globalKill;
}
- bool GlobalEnvironmentMongoD::killOperation(AtomicUInt opId) {
+ bool GlobalEnvironmentMongoD::killOperation(unsigned int opId) {
scoped_lock clientLock(Client::clientsMutex);
bool found = false;
@@ -103,7 +102,7 @@ namespace mongo {
}
}
if ( found ) {
- interruptJs( &opId );
+ interruptJs( opId );
}
return found;
}
diff --git a/src/mongo/db/global_environment_d.h b/src/mongo/db/global_environment_d.h
index a5ee76438fc..2f4d0e88cd5 100644
--- a/src/mongo/db/global_environment_d.h
+++ b/src/mongo/db/global_environment_d.h
@@ -50,7 +50,7 @@ namespace mongo {
bool getKillAllOperations();
- bool killOperation(AtomicUInt opId);
+ bool killOperation(unsigned int opId);
void registerOperationContext(OperationContext* txn);
diff --git a/src/mongo/db/global_environment_experiment.h b/src/mongo/db/global_environment_experiment.h
index d9f4c2dbaf6..30ba29e6d72 100644
--- a/src/mongo/db/global_environment_experiment.h
+++ b/src/mongo/db/global_environment_experiment.h
@@ -29,7 +29,6 @@
#pragma once
#include "mongo/base/disallow_copying.h"
-#include "mongo/bson/util/atomic_int.h"
namespace mongo {
@@ -71,7 +70,7 @@ namespace mongo {
* @param i opid of operation to kill
* @return if operation was found
**/
- virtual bool killOperation(AtomicUInt opId) = 0;
+ virtual bool killOperation(unsigned int opId) = 0;
/**
* Registers the specified operation context on the global environment, so it is
diff --git a/src/mongo/db/global_environment_noop.cpp b/src/mongo/db/global_environment_noop.cpp
index ea8f3c49ca9..4d791a6568c 100644
--- a/src/mongo/db/global_environment_noop.cpp
+++ b/src/mongo/db/global_environment_noop.cpp
@@ -44,7 +44,7 @@ namespace mongo {
return false;
}
- bool GlobalEnvironmentNoop::killOperation(AtomicUInt opId) {
+ bool GlobalEnvironmentNoop::killOperation(unsigned int opId) {
return false;
}
diff --git a/src/mongo/db/global_environment_noop.h b/src/mongo/db/global_environment_noop.h
index bebe2c6047d..6d2f14b377b 100644
--- a/src/mongo/db/global_environment_noop.h
+++ b/src/mongo/db/global_environment_noop.h
@@ -34,7 +34,7 @@ namespace mongo {
public:
StorageEngine* getGlobalStorageEngine();
- bool killOperation(AtomicUInt opId);
+ bool killOperation(unsigned int opId);
void setKillAllOperations();
diff --git a/src/mongo/db/index_builder.cpp b/src/mongo/db/index_builder.cpp
index c6112291149..78af3691d3c 100644
--- a/src/mongo/db/index_builder.cpp
+++ b/src/mongo/db/index_builder.cpp
@@ -44,11 +44,11 @@ namespace mongo {
MONGO_LOG_DEFAULT_COMPONENT_FILE(::mongo::logger::LogComponent::kIndexing);
- AtomicUInt IndexBuilder::_indexBuildCount = 0;
+ AtomicUInt32 IndexBuilder::_indexBuildCount;
IndexBuilder::IndexBuilder(const BSONObj& index) :
BackgroundJob(true /* self-delete */), _index(index.getOwned()),
- _name(str::stream() << "repl index builder " << (_indexBuildCount++).get()) {
+ _name(str::stream() << "repl index builder " << _indexBuildCount.addAndFetch(1)) {
}
IndexBuilder::~IndexBuilder() {}
diff --git a/src/mongo/db/index_builder.h b/src/mongo/db/index_builder.h
index e825794a4c3..1d3699e6671 100644
--- a/src/mongo/db/index_builder.h
+++ b/src/mongo/db/index_builder.h
@@ -33,6 +33,7 @@
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/client.h"
#include "mongo/db/jsobj.h"
+#include "mongo/platform/atomic_word.h"
#include "mongo/util/background.h"
/**
@@ -76,7 +77,7 @@ namespace mongo {
private:
const BSONObj _index;
std::string _name; // name of this builder, not related to the index
- static AtomicUInt _indexBuildCount;
+ static AtomicUInt32 _indexBuildCount;
};
}
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index bf63472c6ba..e9b2fe966fb 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -34,7 +34,6 @@
#include <fstream>
#include "mongo/base/status.h"
-#include "mongo/bson/util/atomic_int.h"
#include "mongo/db/audit.h"
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/authorization_manager.h"
@@ -70,6 +69,7 @@
#include "mongo/db/repl/repl_coordinator_global.h"
#include "mongo/db/stats/counters.h"
#include "mongo/db/storage_options.h"
+#include "mongo/platform/atomic_word.h"
#include "mongo/platform/process_id.h"
#include "mongo/s/d_logic.h"
#include "mongo/s/stale_exception.h" // for SendStaleConfigException
diff --git a/src/mongo/db/operation_context_impl.cpp b/src/mongo/db/operation_context_impl.cpp
index 924c46a1181..ea82457cc9b 100644
--- a/src/mongo/db/operation_context_impl.cpp
+++ b/src/mongo/db/operation_context_impl.cpp
@@ -146,7 +146,7 @@ namespace mongo {
MONGO_FAIL_POINT_BLOCK(checkForInterruptFail, scopedFailPoint) {
if (opShouldFail(c, scopedFailPoint.getData())) {
log() << "set pending kill on " << (c.curop()->parent() ? "nested" : "top-level")
- << " op " << c.curop()->opNum().get() << ", for checkForInterruptFail";
+ << " op " << c.curop()->opNum() << ", for checkForInterruptFail";
c.curop()->kill();
}
}
@@ -171,7 +171,7 @@ namespace mongo {
MONGO_FAIL_POINT_BLOCK(checkForInterruptFail, scopedFailPoint) {
if (opShouldFail(c, scopedFailPoint.getData())) {
log() << "set pending kill on " << (c.curop()->parent() ? "nested" : "top-level")
- << " op " << c.curop()->opNum().get() << ", for checkForInterruptFail";
+ << " op " << c.curop()->opNum() << ", for checkForInterruptFail";
c.curop()->kill();
}
}
diff --git a/src/mongo/db/repl/rs_config.cpp b/src/mongo/db/repl/rs_config.cpp
index 65b70dd9c01..0544ff05d1b 100644
--- a/src/mongo/db/repl/rs_config.cpp
+++ b/src/mongo/db/repl/rs_config.cpp
@@ -55,7 +55,7 @@ namespace repl {
const int ReplSetConfig::DEFAULT_HB_TIMEOUT = 10;
namespace {
- AtomicUInt _warnedAboutVotes = 0;
+ AtomicUInt32 _warnedAboutVotes;
void assertOnlyHas(BSONObj o, const set<string>& fields) {
BSONObj::iterator i(o);
@@ -534,7 +534,7 @@ namespace {
m.priority = mobj["priority"].Number();
if( mobj.hasElement("votes") )
m.votes = (unsigned) mobj["votes"].Number();
- if (m.votes > 1 && !_warnedAboutVotes) {
+ if (m.votes > 1 && (_warnedAboutVotes.load() == 0)) {
log() << "\t\tWARNING: Having more than 1 vote on a single replicaset member is"
<< startupWarningsLog;
log() << "\t\tdeprecated, as it causes issues with majority write concern. For"
@@ -542,7 +542,7 @@ namespace {
log() << "\t\tmore information, see "
<< "http://dochub.mongodb.org/core/replica-set-votes-deprecated"
<< startupWarningsLog;
- _warnedAboutVotes.set(1);
+ _warnedAboutVotes.store(1);
}
if( mobj.hasElement("tags") ) {
const BSONObj &t = mobj["tags"].Obj();
diff --git a/src/mongo/db/sorter/sorter.cpp b/src/mongo/db/sorter/sorter.cpp
index c2a39a1e0b2..113813d22f3 100644
--- a/src/mongo/db/sorter/sorter.cpp
+++ b/src/mongo/db/sorter/sorter.cpp
@@ -51,9 +51,9 @@
#include <snappy.h>
#include "mongo/base/string_data.h"
-#include "mongo/bson/util/atomic_int.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/storage_options.h"
+#include "mongo/platform/atomic_word.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/bufreader.h"
#include "mongo/util/goodies.h"
@@ -765,8 +765,8 @@ namespace mongo {
inline unsigned nextFileNumber() {
// This is unified across all Sorter types and instances.
- static AtomicUInt fileCounter;
- return fileCounter++;
+ static AtomicUInt32 fileCounter;
+ return fileCounter.fetchAndAdd(1);
}
} // namespace sorter
diff --git a/src/mongo/db/stats/counters.cpp b/src/mongo/db/stats/counters.cpp
index a50aca7eeba..eba6ae93b0b 100644
--- a/src/mongo/db/stats/counters.cpp
+++ b/src/mongo/db/stats/counters.cpp
@@ -39,37 +39,37 @@ namespace mongo {
void OpCounters::incInsertInWriteLock(int n) {
RARELY _checkWrap();
- _insert.x += n;
+ _insert.fetchAndAdd(n);
}
void OpCounters::gotInsert() {
RARELY _checkWrap();
- _insert++;
+ _insert.fetchAndAdd(1);
}
void OpCounters::gotQuery() {
RARELY _checkWrap();
- _query++;
+ _query.fetchAndAdd(1);
}
void OpCounters::gotUpdate() {
RARELY _checkWrap();
- _update++;
+ _update.fetchAndAdd(1);
}
void OpCounters::gotDelete() {
RARELY _checkWrap();
- _delete++;
+ _delete.fetchAndAdd(1);
}
void OpCounters::gotGetMore() {
RARELY _checkWrap();
- _getmore++;
+ _getmore.fetchAndAdd(1);
}
void OpCounters::gotCommand() {
RARELY _checkWrap();
- _command++;
+ _command.fetchAndAdd(1);
}
void OpCounters::gotOp( int op , bool isCommand ) {
@@ -97,31 +97,31 @@ namespace mongo {
const unsigned MAX = 1 << 30;
bool wrap =
- _insert.get() > MAX ||
- _query.get() > MAX ||
- _update.get() > MAX ||
- _delete.get() > MAX ||
- _getmore.get() > MAX ||
- _command.get() > MAX;
+ _insert.loadRelaxed() > MAX ||
+ _query.loadRelaxed() > MAX ||
+ _update.loadRelaxed() > MAX ||
+ _delete.loadRelaxed() > MAX ||
+ _getmore.loadRelaxed() > MAX ||
+ _command.loadRelaxed() > MAX;
if ( wrap ) {
- _insert.zero();
- _query.zero();
- _update.zero();
- _delete.zero();
- _getmore.zero();
- _command.zero();
+ _insert.store(0);
+ _query.store(0);
+ _update.store(0);
+ _delete.store(0);
+ _getmore.store(0);
+ _command.store(0);
}
}
BSONObj OpCounters::getObj() const {
BSONObjBuilder b;
- b.append( "insert" , _insert.get() );
- b.append( "query" , _query.get() );
- b.append( "update" , _update.get() );
- b.append( "delete" , _delete.get() );
- b.append( "getmore" , _getmore.get() );
- b.append( "command" , _command.get() );
+ b.append( "insert" , _insert.loadRelaxed() );
+ b.append( "query" , _query.loadRelaxed() );
+ b.append( "update" , _update.loadRelaxed() );
+ b.append( "delete" , _delete.loadRelaxed() );
+ b.append( "getmore" , _getmore.loadRelaxed() );
+ b.append( "command" , _command.loadRelaxed() );
return b.obj();
}
diff --git a/src/mongo/db/stats/counters.h b/src/mongo/db/stats/counters.h
index b0aad7a7ce6..d9c54242cb4 100644
--- a/src/mongo/db/stats/counters.h
+++ b/src/mongo/db/stats/counters.h
@@ -30,8 +30,8 @@
#pragma once
#include "mongo/pch.h"
-#include "mongo/bson/util/atomic_int.h"
#include "mongo/db/jsobj.h"
+#include "mongo/platform/atomic_word.h"
#include "mongo/util/net/message.h"
#include "mongo/util/processinfo.h"
#include "mongo/util/concurrency/spin_lock.h"
@@ -59,25 +59,24 @@ namespace mongo {
BSONObj getObj() const;
// thse are used by snmp, and other things, do not remove
- const AtomicUInt * getInsert() const { return &_insert; }
- const AtomicUInt * getQuery() const { return &_query; }
- const AtomicUInt * getUpdate() const { return &_update; }
- const AtomicUInt * getDelete() const { return &_delete; }
- const AtomicUInt * getGetMore() const { return &_getmore; }
- const AtomicUInt * getCommand() const { return &_command; }
-
+ const AtomicUInt32 * getInsert() const { return &_insert; }
+ const AtomicUInt32 * getQuery() const { return &_query; }
+ const AtomicUInt32 * getUpdate() const { return &_update; }
+ const AtomicUInt32 * getDelete() const { return &_delete; }
+ const AtomicUInt32 * getGetMore() const { return &_getmore; }
+ const AtomicUInt32 * getCommand() const { return &_command; }
private:
void _checkWrap();
// todo: there will be a lot of cache line contention on these. need to do something
// else eventually.
- AtomicUInt _insert;
- AtomicUInt _query;
- AtomicUInt _update;
- AtomicUInt _delete;
- AtomicUInt _getmore;
- AtomicUInt _command;
+ AtomicUInt32 _insert;
+ AtomicUInt32 _query;
+ AtomicUInt32 _update;
+ AtomicUInt32 _delete;
+ AtomicUInt32 _getmore;
+ AtomicUInt32 _command;
};
extern OpCounters globalOpCounters;