1
0
Fork 0

Merge branch 'devel' of https://github.com/arangodb/arangodb into readcache

This commit is contained in:
jsteemann 2016-08-02 12:59:06 +02:00
commit f44effd225
2 changed files with 14 additions and 17 deletions

View File

@ -144,10 +144,6 @@ class HybridLogicalClock {
return r; return r;
} }
private:
// helper to compute the offset between epoch and 1970
uint64_t computeOffset1970();
// helper to get the physical time in milliseconds since the epoch: // helper to get the physical time in milliseconds since the epoch:
uint64_t getPhysicalTime() { uint64_t getPhysicalTime() {
auto now = _clock.now(); auto now = _clock.now();
@ -158,6 +154,10 @@ class HybridLogicalClock {
return ms; return ms;
} }
private:
// helper to compute the offset between epoch and 1970
uint64_t computeOffset1970();
static uint64_t extractTime(uint64_t t) { return t >> 20; } static uint64_t extractTime(uint64_t t) { return t >> 20; }
static uint64_t extractCount(uint64_t t) { return t & 0xfffffUL; } static uint64_t extractCount(uint64_t t) { return t & 0xfffffUL; }

View File

@ -31,7 +31,9 @@
#endif #endif
#include "Basics/Exceptions.h" #include "Basics/Exceptions.h"
#include "Basics/HybridLogicalClock.h"
#include "Basics/Thread.h" #include "Basics/Thread.h"
#include "Basics/hashes.h"
#include "Logger/Logger.h" #include "Logger/Logger.h"
using namespace arangodb; using namespace arangodb;
@ -42,16 +44,12 @@ using namespace arangodb::basics;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
unsigned long RandomDevice::seed() { unsigned long RandomDevice::seed() {
unsigned long s = (unsigned long)time(0); HybridLogicalClock clock;
unsigned long s = static_cast<unsigned long>(clock.getPhysicalTime());
struct timeval tv; TRI_pid_t pid = Thread::currentProcessId();
int result = gettimeofday(&tv, 0);
s ^= static_cast<unsigned long>(tv.tv_sec);
s ^= static_cast<unsigned long>(tv.tv_usec);
s ^= static_cast<unsigned long>(result);
s ^= static_cast<unsigned long>(Thread::currentProcessId());
s ^= static_cast<unsigned long>(TRI_Crc32HashPointer(&pid, sizeof(TRI_pid_t)));
s = static_cast<unsigned long>(TRI_Crc32HashPointer(&s, sizeof(unsigned long)));
return s; return s;
} }
@ -353,8 +351,7 @@ class RandomDeviceCombined : public RandomDevice {
class RandomDeviceMersenne : public RandomDevice { class RandomDeviceMersenne : public RandomDevice {
public: public:
RandomDeviceMersenne() RandomDeviceMersenne()
: engine(static_cast<unsigned int>( : engine(RandomDevice::seed()) {}
std::chrono::system_clock::now().time_since_epoch().count())) {}
uint32_t random() { return engine(); } uint32_t random() { return engine(); }