ObjectId::MachineAndPid ObjectId::genMachineAndPid() { qint64 n = QScopedPointer<SecureRandom>(SecureRandom::create())->nextInt64(); ObjectId::MachineAndPid x = ourMachine = reinterpret_cast<ObjectId::MachineAndPid&>(n); foldInPid(x); return x; }
void OID::justForked() { MachineAndPid x = ourMachine; // we let the random # for machine go into all 5 bytes of MachineAndPid, and then // xor in the pid into _pid. this reduces the probability of collisions. foldInPid(x); ourMachineAndPid = genMachineAndPid(); verify( x != ourMachineAndPid ); ourMachineAndPid = x; }
OID::MachineAndPid OID::genMachineAndPid() { BOOST_STATIC_ASSERT( sizeof(mongo::OID::MachineAndPid) == 5 ); // we only call this once per process scoped_ptr<SecureRandom> sr( SecureRandom::create() ); int64_t n = sr->nextInt64(); OID::MachineAndPid x = ourMachine = reinterpret_cast<OID::MachineAndPid&>(n); foldInPid(x); return x; }
OID::MachineAndPid OID::genMachineAndPid() { BOOST_STATIC_ASSERT( sizeof(mongo::OID::MachineAndPid) == 5 ); // 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. { nonce64 a = Security::getNonceDuringInit(); nonce64 b = Security::getNonceDuringInit(); nonce64 c = Security::getNonceDuringInit(); verify( !(a==b && b==c) ); } unsigned long long n = Security::getNonceDuringInit(); OID::MachineAndPid x = ourMachine = (OID::MachineAndPid&) n; foldInPid(x); return x; }
static OID::MachineAndPid __gen() { unsigned long long n = security.getNonce(); OID::MachineAndPid x = ourMachine = (OID::MachineAndPid&) n; foldInPid(x); return x; }