summaryrefslogtreecommitdiff
path: root/src/mongo/bson/oid.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2012-06-04 23:38:38 -0400
committerEliot Horowitz <eliot@10gen.com>2012-06-04 23:41:32 -0400
commitbc777ecffcd13674129f5205a63d45ea8707dd4b (patch)
tree17c4d37d6ec2c11c03b2246eb822c3b588bfef9b /src/mongo/bson/oid.cpp
parent78f183186136b8271af4ec253e4bcb2bf0bbdbac (diff)
downloadmongo-bc777ecffcd13674129f5205a63d45ea8707dd4b.tar.gz
add OID::initSequential
Diffstat (limited to 'src/mongo/bson/oid.cpp')
-rw-r--r--src/mongo/bson/oid.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/mongo/bson/oid.cpp b/src/mongo/bson/oid.cpp
index fb7d6ead891..4f25fef6085 100644
--- a/src/mongo/bson/oid.cpp
+++ b/src/mongo/bson/oid.cpp
@@ -19,6 +19,7 @@
#include <boost/functional/hash.hpp>
+#include "mongo/platform/atomic_uint64.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/bson/oid.h"
#include "mongo/bson/util/atomic_int.h"
@@ -135,6 +136,27 @@ namespace mongo {
}
}
+ void OID::initSequential() {
+ static AtomicUInt64 sequence;
+
+ {
+ unsigned t = (unsigned) time(0);
+ unsigned char *T = (unsigned char *) &t;
+ _time[0] = T[3]; // big endian order because we use memcmp() to compare OID's
+ _time[1] = T[2];
+ _time[2] = T[1];
+ _time[3] = T[0];
+ }
+
+ {
+ unsigned long long nextNumber = sequence.fetchAndAdd();
+ unsigned char* numberData = reinterpret_cast<unsigned char*>(&nextNumber);
+ for ( int i=0; i<8; i++ ) {
+ data[4+i] = numberData[7-i];
+ }
+ }
+ }
+
void OID::init( string s ) {
verify( s.size() == 24 );
const char *p = s.c_str();