remove constexpr from util/random.h for MSVC compat

Summary:
Scoped anonymous enums seem to be better supported than static
constexpr at the moment, so this diff replaces the latter with the former.
Also, this diff removes an incorrect inclusion of pthread.h.  MSVC build
was broken starting with D50439.

Test Plan:
1. build
2. observe proper skiplist behavior by absence of pathological slowdown
3. push diff to tmp_try_windows branch to tickle AppVeyor
4. wait for contbuild before committing to master

Reviewers: sdong

Reviewed By: sdong

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D50517
main
Nathan Bronson 9 years ago
parent b81b430987
commit 505accda38
  1. 9
      util/random.cc
  2. 10
      util/random.h

@ -6,9 +6,10 @@
#include "util/random.h"
#include <pthread.h>
#include <stdint.h>
#include <string.h>
#include <thread>
#include <utility>
#include "port/likely.h"
#include "util/thread_local.h"
@ -27,10 +28,8 @@ Random* Random::GetTLSInstance() {
auto rv = tls_instance;
if (UNLIKELY(rv == nullptr)) {
const pthread_t self = pthread_self();
uint32_t seed = 0;
memcpy(&seed, &self, sizeof(seed));
rv = new (&tls_instance_bytes) Random(seed);
size_t seed = std::hash<std::thread::id>()(std::this_thread::get_id());
rv = new (&tls_instance_bytes) Random((uint32_t)seed);
tls_instance = rv;
}
return rv;

@ -18,8 +18,12 @@ namespace rocksdb {
// package.
class Random {
private:
static constexpr uint32_t M = 2147483647L; // 2^31-1
static constexpr uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0
enum : uint32_t {
M = 2147483647L // 2^31-1
};
enum : uint64_t {
A = 16807 // bits 14, 8, 7, 5, 2, 1, 0
};
uint32_t seed_;
@ -27,7 +31,7 @@ class Random {
public:
// This is the largest value that can be returned from Next()
static constexpr uint32_t kMaxNext = M;
enum : uint32_t { kMaxNext = M };
explicit Random(uint32_t s) : seed_(GoodSeed(s)) {}

Loading…
Cancel
Save