diff options
author | Antonin Kral <a.kral@bobek.cz> | 2011-09-14 17:08:06 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2011-09-14 17:08:06 +0200 |
commit | 5d342a758c6095b4d30aba0750b54f13b8916f51 (patch) | |
tree | 762e9aa84781f5e3b96db2c02d356c29cf0217c0 /bson/oid.cpp | |
parent | cbe2d992e9cd1ea66af9fa91df006106775d3073 (diff) | |
download | mongodb-5d342a758c6095b4d30aba0750b54f13b8916f51.tar.gz |
Imported Upstream version 2.0.0
Diffstat (limited to 'bson/oid.cpp')
-rw-r--r-- | bson/oid.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/bson/oid.cpp b/bson/oid.cpp index 6aa0730..3aee14a 100644 --- a/bson/oid.cpp +++ b/bson/oid.cpp @@ -19,6 +19,7 @@ #include "oid.h" #include "util/atomic_int.h" #include "../db/nonce.h" +#include "bsonobjbuilder.h" BOOST_STATIC_ASSERT( sizeof(mongo::OID) == 12 ); @@ -34,7 +35,7 @@ namespace mongo { #elif defined(__linux__) || defined(__APPLE__) || defined(__sunos__) pid = (unsigned short) getpid(); #else - pid = (unsigned short) security.getNonce(); + pid = (unsigned short) Security::getNonce(); #endif return pid; } @@ -53,13 +54,13 @@ namespace mongo { // this is not called often, so the following is not expensive, and gives us some // testing that nonce generation is working right and that our OIDs are (perhaps) ok. { - nonce a = security.getNonce(); - nonce b = security.getNonce(); - nonce c = security.getNonce(); + nonce64 a = Security::getNonceDuringInit(); + nonce64 b = Security::getNonceDuringInit(); + nonce64 c = Security::getNonceDuringInit(); assert( !(a==b && b==c) ); } - unsigned long long n = security.getNonce(); + unsigned long long n = Security::getNonceDuringInit(); OID::MachineAndPid x = ourMachine = (OID::MachineAndPid&) n; foldInPid(x); return x; @@ -96,7 +97,7 @@ namespace mongo { } void OID::init() { - static AtomicUInt inc = (unsigned) security.getNonce(); + static AtomicUInt inc = (unsigned) Security::getNonce(); { unsigned t = (unsigned) time(0); @@ -151,4 +152,22 @@ namespace mongo { return time; } + const string BSONObjBuilder::numStrs[] = { + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", + "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", + "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", + "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", + "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", + "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", + "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", + "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", + "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", + "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", + }; + + // This is to ensure that BSONObjBuilder doesn't try to use numStrs before the strings have been constructed + // I've tested just making numStrs a char[][], but the overhead of constructing the strings each time was too high + // numStrsReady will be 0 until after numStrs is initialized because it is a static variable + bool BSONObjBuilder::numStrsReady = (numStrs[0].size() > 0); + } |