summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2018-05-23 12:54:08 -0400
committerAndrew Morrow <acm@mongodb.com>2018-05-23 16:11:39 -0400
commit56ec2fc78cb0d2d6e3850b2df06eb0d5b4f487f4 (patch)
treed30e29e829b755f755ce8047b9c08e35c39bd312 /src/mongo
parent908df56a8ef1f5f599bf4797dfee7838e326a2ee (diff)
downloadmongo-56ec2fc78cb0d2d6e3850b2df06eb0d5b4f487f4.tar.gz
SERVER-35170 Add misc fixes to enable building in -std=c++17 mode
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/client/replica_set_monitor.cpp6
-rw-r--r--src/mongo/db/repl/idempotency_update_sequence.cpp2
-rw-r--r--src/mongo/db/sorter/sorter_test.cpp6
-rw-r--r--src/mongo/platform/random.h37
-rw-r--r--src/mongo/stdx/new.h2
-rw-r--r--src/mongo/util/net/ssl_manager_apple.cpp40
6 files changed, 67 insertions, 26 deletions
diff --git a/src/mongo/client/replica_set_monitor.cpp b/src/mongo/client/replica_set_monitor.cpp
index 6d8c60dafde..a6ff0330df8 100644
--- a/src/mongo/client/replica_set_monitor.cpp
+++ b/src/mongo/client/replica_set_monitor.cpp
@@ -667,8 +667,8 @@ ScanStatePtr Refresher::startNewScan(const SetState* set) {
}
// shuffle the queue, but keep "up" nodes at the front
- std::random_shuffle(scan->hostsToScan.begin(), scan->hostsToScan.begin() + upNodes, set->rand);
- std::random_shuffle(scan->hostsToScan.begin() + upNodes, scan->hostsToScan.end(), set->rand);
+ std::shuffle(scan->hostsToScan.begin(), scan->hostsToScan.begin() + upNodes, set->rand.urbg());
+ std::shuffle(scan->hostsToScan.begin() + upNodes, scan->hostsToScan.end(), set->rand.urbg());
if (!set->lastSeenMaster.empty()) {
// move lastSeenMaster to front of queue
@@ -1297,6 +1297,6 @@ void ScanState::enqueAllUntriedHosts(const Container& container, PseudoRandom& r
hostsToScan.push_back(*it);
}
}
- std::random_shuffle(hostsToScan.begin(), hostsToScan.end(), rand);
+ std::shuffle(hostsToScan.begin(), hostsToScan.end(), rand.urbg());
}
}
diff --git a/src/mongo/db/repl/idempotency_update_sequence.cpp b/src/mongo/db/repl/idempotency_update_sequence.cpp
index 24335b5b5f9..7c9429a49af 100644
--- a/src/mongo/db/repl/idempotency_update_sequence.cpp
+++ b/src/mongo/db/repl/idempotency_update_sequence.cpp
@@ -276,7 +276,7 @@ UpdateSequenceGenerator::UpdateSequenceGenerator(UpdateSequenceGeneratorConfig c
auto path = "";
_generatePaths(config, path);
// Creates the same shuffle each time, but we don't care. We want to mess up the DFS ordering.
- std::random_shuffle(this->_paths.begin(), this->_paths.end(), this->_random);
+ std::shuffle(this->_paths.begin(), this->_paths.end(), this->_random.urbg());
}
} // namespace mongo
diff --git a/src/mongo/db/sorter/sorter_test.cpp b/src/mongo/db/sorter/sorter_test.cpp
index 3ba4e8a98c3..6fb550b24cd 100644
--- a/src/mongo/db/sorter/sorter_test.cpp
+++ b/src/mongo/db/sorter/sorter_test.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_noop.h"
#include "mongo/db/service_context_registrar.h"
+#include "mongo/platform/random.h"
#include "mongo/stdx/thread.h"
#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
@@ -477,12 +478,12 @@ class Dupes : public Basic {
template <bool Random = true>
class LotsOfDataLittleMemory : public Basic {
public:
- LotsOfDataLittleMemory() : _array(new int[NUM_ITEMS]) {
+ LotsOfDataLittleMemory() : _array(new int[NUM_ITEMS]), _random(int64_t(time(0))) {
for (int i = 0; i < NUM_ITEMS; i++)
_array[i] = i;
if (Random)
- std::random_shuffle(_array.get(), _array.get() + NUM_ITEMS);
+ std::shuffle(_array.get(), _array.get() + NUM_ITEMS, _random.urbg());
}
SortOptions adjustSortOptions(SortOptions opts) {
@@ -516,6 +517,7 @@ public:
MEM_LIMIT = 64 * 1024,
};
std::unique_ptr<int[]> _array;
+ PseudoRandom _random;
};
diff --git a/src/mongo/platform/random.h b/src/mongo/platform/random.h
index cff30f0ecd0..28a0c7526d2 100644
--- a/src/mongo/platform/random.h
+++ b/src/mongo/platform/random.h
@@ -30,6 +30,7 @@
#pragma once
#include <cstdint>
+#include <limits>
#include <memory>
namespace mongo {
@@ -69,14 +70,36 @@ public:
}
/**
- * @return a number between 0 and max
- *
- * This makes PseudoRandom instances passable as the third argument to std::random_shuffle
+ * This returns an object that adapts PseudoRandom such that it
+ * can be used as the third argument to std::shuffle. Note that
+ * the lifetime of the returned object must be a subset of the
+ * lifetime of the PseudoRandom object.
*/
- intptr_t operator()(intptr_t max) {
- if (sizeof(intptr_t) == 4)
- return static_cast<intptr_t>(nextInt32(static_cast<int32_t>(max)));
- return static_cast<intptr_t>(nextInt64(static_cast<int64_t>(max)));
+ auto urbg() {
+
+ class URBG {
+ public:
+ explicit URBG(PseudoRandom* impl) : _impl(impl) {}
+
+ using result_type = uint64_t;
+
+ static constexpr result_type min() {
+ return std::numeric_limits<result_type>::min();
+ }
+
+ static constexpr result_type max() {
+ return std::numeric_limits<result_type>::max();
+ }
+
+ result_type operator()() {
+ return _impl->nextInt64();
+ }
+
+ private:
+ PseudoRandom* _impl;
+ };
+
+ return URBG(this);
}
private:
diff --git a/src/mongo/stdx/new.h b/src/mongo/stdx/new.h
index 158223d35d2..9afe9820d76 100644
--- a/src/mongo/stdx/new.h
+++ b/src/mongo/stdx/new.h
@@ -36,7 +36,7 @@
namespace mongo {
namespace stdx {
-#if __cplusplus < 201703L
+#if __cplusplus < 201703L || !defined(__cpp_lib_hardware_interference_size)
#if defined(MONGO_CONFIG_MAX_EXTENDED_ALIGNMENT)
static_assert(MONGO_CONFIG_MAX_EXTENDED_ALIGNMENT >= sizeof(uint64_t), "Bad extended alignment");
diff --git a/src/mongo/util/net/ssl_manager_apple.cpp b/src/mongo/util/net/ssl_manager_apple.cpp
index 01569048e24..3bac7ce6b39 100644
--- a/src/mongo/util/net/ssl_manager_apple.cpp
+++ b/src/mongo/util/net/ssl_manager_apple.cpp
@@ -215,47 +215,63 @@ bool isUnixDomainSocket(const std::string& hostname) {
namespace detail {
template <typename T>
-struct CFTypeMap {};
+struct CFTypeMap;
+
template <>
struct CFTypeMap<::CFStringRef> {
- static constexpr StringData typeName = "string"_sd;
+ static constexpr StringData typeName() {
+ return "string"_sd;
+ }
+
static ::CFTypeID type() {
return ::CFStringGetTypeID();
}
};
-constexpr StringData CFTypeMap<::CFStringRef>::typeName;
+
template <>
struct CFTypeMap<::CFDataRef> {
- static constexpr StringData typeName = "data"_sd;
+ static constexpr StringData typeName() {
+ return "data"_sd;
+ }
+
static ::CFTypeID type() {
return ::CFDataGetTypeID();
}
};
-constexpr StringData CFTypeMap<::CFDataRef>::typeName;
+
template <>
struct CFTypeMap<::CFNumberRef> {
- static constexpr StringData typeName = "number"_sd;
+ static constexpr StringData typeName() {
+ return "number"_sd;
+ }
+
static ::CFTypeID type() {
return ::CFNumberGetTypeID();
}
};
-constexpr StringData CFTypeMap<::CFNumberRef>::typeName;
+
template <>
struct CFTypeMap<::CFArrayRef> {
- static constexpr StringData typeName = "array"_sd;
+ static constexpr StringData typeName() {
+ return "array"_sd;
+ }
+
static ::CFTypeID type() {
return ::CFArrayGetTypeID();
}
};
-constexpr StringData CFTypeMap<::CFArrayRef>::typeName;
+
template <>
struct CFTypeMap<::CFDictionaryRef> {
- static constexpr StringData typeName = "dictionary"_sd;
+ static constexpr StringData typeName() {
+ return "dictionary"_sd;
+ }
+
static ::CFTypeID type() {
return ::CFDictionaryGetTypeID();
}
};
-constexpr StringData CFTypeMap<::CFDictionaryRef>::typeName;
+
} // namespace detail
template <typename T>
@@ -274,7 +290,7 @@ StatusWith<T> extractDictionaryValue(::CFDictionaryRef dict, ::CFStringRef key)
return badValue("Missing value");
}
if (::CFGetTypeID(val) != detail::CFTypeMap<T>::type()) {
- return badValue(str::stream() << "Value is not a " << detail::CFTypeMap<T>::typeName);
+ return badValue(str::stream() << "Value is not a " << detail::CFTypeMap<T>::typeName());
}
return reinterpret_cast<T>(val);
}