Files
mongo/db/common.cpp

69 lines
2.4 KiB
C++
Raw Normal View History

2011-07-15 10:37:07 -04:00
/** @file common.cpp Common code for server binaries (mongos, mongod, test). Nothing used by driver should be here. */
2011-06-17 14:57:16 -04:00
2010-06-04 10:25:07 -04:00
/*
* Copyright (C) 2010 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2010-02-07 01:38:54 -05:00
2010-04-27 15:27:52 -04:00
#include "pch.h"
2010-02-07 01:38:54 -05:00
#include "concurrency.h"
#include "jsobjmanipulator.h"
2010-02-07 01:38:54 -05:00
/**
* this just has globals
*/
namespace mongo {
2011-06-17 14:57:16 -04:00
/** called by mongos, mongod, test. do not call from clients and such.
invoked before about everything except global var construction.
*/
void doPreServerStatupInits() {
}
2010-02-07 01:38:54 -05:00
/* we use new here so we don't have to worry about destructor orders at program shutdown */
2011-05-10 12:40:01 -04:00
MongoMutex &dbMutex( *(new MongoMutex("dbMutex")) );
2010-02-07 01:38:54 -05:00
2011-01-04 00:40:41 -05:00
MongoMutex::MongoMutex(const char *name) : _m(name) {
2011-04-06 11:27:58 -04:00
static int n = 0;
2011-04-06 10:56:03 -04:00
assert( ++n == 1 ); // below releasingWriteLock we assume MongoMutex is a singleton, and uses dbMutex ref above
2010-11-27 15:25:08 -05:00
_remapPrivateViewRequested = false;
}
// OpTime::now() uses dbMutex, thus it is in this file not in the cpp files used by drivers and such
void BSONElementManipulator::initTimestamp() {
massert( 10332 , "Expected CurrentTime type", _element.type() == Timestamp );
unsigned long long &timestamp = *( reinterpret_cast< unsigned long long* >( value() ) );
if ( timestamp == 0 )
timestamp = OpTime::now().asDate();
}
NOINLINE_DECL OpTime OpTime::skewed() {
bool toLog = false;
ONCE toLog = true;
RARELY toLog = true;
last.i++;
if ( last.i & 0x80000000 )
toLog = true;
if ( toLog ) {
log() << "clock skew detected prev: " << last.secs << " now: " << (unsigned) time(0) << endl;
}
if ( last.i & 0x80000000 ) {
log() << "error large clock skew detected, shutting down" << endl;
throw ClockSkewException();
}
return last;
}
2010-02-07 01:38:54 -05:00
}