summaryrefslogtreecommitdiff
path: root/src/mongo/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/util')
-rw-r--r--src/mongo/util/SConscript2
-rw-r--r--src/mongo/util/assert_util.h21
-rw-r--r--src/mongo/util/background.cpp7
-rw-r--r--src/mongo/util/background_thread_clock_source.cpp3
-rw-r--r--src/mongo/util/base64.cpp2
-rw-r--r--src/mongo/util/base64.h3
-rw-r--r--src/mongo/util/bufreader.h1
-rw-r--r--src/mongo/util/concurrency/synchronization.h2
-rw-r--r--src/mongo/util/destructor_guard.h50
-rw-r--r--src/mongo/util/duration.cpp2
-rw-r--r--src/mongo/util/duration.h49
-rw-r--r--src/mongo/util/duration_test.cpp30
-rw-r--r--src/mongo/util/net/sock.h1
-rw-r--r--src/mongo/util/ntservice.cpp2
-rw-r--r--src/mongo/util/processinfo.h1
-rw-r--r--src/mongo/util/text.cpp3
-rw-r--r--src/mongo/util/time_support.cpp63
-rw-r--r--src/mongo/util/time_support.h42
-rw-r--r--src/mongo/util/time_support_test.cpp4
19 files changed, 134 insertions, 154 deletions
diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript
index f2d3763c858..d1716c98713 100644
--- a/src/mongo/util/SConscript
+++ b/src/mongo/util/SConscript
@@ -494,7 +494,7 @@ env.CppUnitTest(
target='duration_test',
source=[
'duration_test.cpp',
- 'duration.cpp',
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/base',
])
diff --git a/src/mongo/util/assert_util.h b/src/mongo/util/assert_util.h
index 82369810174..1d72c045764 100644
--- a/src/mongo/util/assert_util.h
+++ b/src/mongo/util/assert_util.h
@@ -31,10 +31,8 @@
#include <string>
#include "mongo/base/status.h" // NOTE: This is safe as utils depend on base
+#include "mongo/base/status_with.h"
#include "mongo/platform/compiler.h"
-#include "mongo/logger/log_severity.h"
-#include "mongo/logger/logger.h"
-#include "mongo/logger/logstream_builder.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/debug_util.h"
@@ -380,23 +378,6 @@ Status exceptionToStatus();
msgasserted(14044, std::string("unknown exception") + msg); \
}
-#define DESTRUCTOR_GUARD MONGO_DESTRUCTOR_GUARD
-#define MONGO_DESTRUCTOR_GUARD(expression) \
- try { \
- expression; \
- } catch (const std::exception& e) { \
- ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
- ::mongo::getThreadName(), \
- ::mongo::logger::LogSeverity::Log()) \
- << "caught exception (" << e.what() << ") in destructor (" << __FUNCTION__ << ")" \
- << std::endl; \
- } catch (...) { \
- ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
- ::mongo::getThreadName(), \
- ::mongo::logger::LogSeverity::Log()) \
- << "caught unknown exception in destructor (" << __FUNCTION__ << ")" << std::endl; \
- }
-
/**
* The purpose of this macro is to instruct the compiler that a line of code will never be reached.
*
diff --git a/src/mongo/util/background.cpp b/src/mongo/util/background.cpp
index 11eab0e06d1..bc6c293b1bb 100644
--- a/src/mongo/util/background.cpp
+++ b/src/mongo/util/background.cpp
@@ -200,11 +200,12 @@ Status BackgroundJob::cancel() {
bool BackgroundJob::wait(unsigned msTimeOut) {
verify(!_selfDelete); // you cannot call wait on a self-deleting job
- const auto deadline = stdx::chrono::system_clock::now() + Milliseconds(msTimeOut);
+ const auto deadline = Date_t::now() + Milliseconds(msTimeOut);
stdx::unique_lock<stdx::mutex> l(_status->mutex);
while (_status->state != Done) {
if (msTimeOut) {
- if (stdx::cv_status::timeout == _status->done.wait_until(l, deadline))
+ if (stdx::cv_status::timeout ==
+ _status->done.wait_until(l, deadline.toSystemTimePoint()))
return false;
} else {
_status->done.wait(l);
@@ -308,7 +309,7 @@ void PeriodicTaskRunner::run() {
stdx::unique_lock<stdx::mutex> lock(_mutex);
while (!_shutdownRequested) {
- if (stdx::cv_status::timeout == _cond.wait_for(lock, waitTime))
+ if (stdx::cv_status::timeout == _cond.wait_for(lock, waitTime.toSystemDuration()))
_runTasks();
}
}
diff --git a/src/mongo/util/background_thread_clock_source.cpp b/src/mongo/util/background_thread_clock_source.cpp
index 3a2d43c1f82..81b4666760b 100644
--- a/src/mongo/util/background_thread_clock_source.cpp
+++ b/src/mongo/util/background_thread_clock_source.cpp
@@ -70,7 +70,8 @@ void BackgroundThreadClockSource::_startTimerThread() {
_timer = stdx::thread([&]() {
stdx::unique_lock<stdx::mutex> lock(_mutex);
while (!_shutdownTimer) {
- if (_condition.wait_for(lock, _granularity) == stdx::cv_status::timeout) {
+ if (_condition.wait_for(lock, _granularity.toSystemDuration()) ==
+ stdx::cv_status::timeout) {
_updateCurrent();
}
}
diff --git a/src/mongo/util/base64.cpp b/src/mongo/util/base64.cpp
index 6938b318148..59fdfb63872 100644
--- a/src/mongo/util/base64.cpp
+++ b/src/mongo/util/base64.cpp
@@ -32,6 +32,8 @@
#include "mongo/util/base64.h"
+#include <sstream>
+
namespace mongo {
using std::string;
diff --git a/src/mongo/util/base64.h b/src/mongo/util/base64.h
index 388e0f9cf1d..d5cf3a71f55 100644
--- a/src/mongo/util/base64.h
+++ b/src/mongo/util/base64.h
@@ -29,6 +29,9 @@
#pragma once
+#include <memory>
+#include <iosfwd>
+#include <string>
#include "mongo/util/assert_util.h"
diff --git a/src/mongo/util/bufreader.h b/src/mongo/util/bufreader.h
index 58e7c5d2816..ae7f2a469e3 100644
--- a/src/mongo/util/bufreader.h
+++ b/src/mongo/util/bufreader.h
@@ -33,6 +33,7 @@
#include "mongo/base/data_range.h"
#include "mongo/base/data_range_cursor.h"
#include "mongo/base/data_type_terminated.h"
+#include "mongo/base/disallow_copying.h"
#include "mongo/bson/util/builder.h"
#include "mongo/platform/strnlen.h"
#include "mongo/util/assert_util.h"
diff --git a/src/mongo/util/concurrency/synchronization.h b/src/mongo/util/concurrency/synchronization.h
index 655ddfb149d..aa611e981f1 100644
--- a/src/mongo/util/concurrency/synchronization.h
+++ b/src/mongo/util/concurrency/synchronization.h
@@ -30,7 +30,7 @@
#pragma once
#include "mongo/stdx/condition_variable.h"
-
+#include "mongo/stdx/mutex.h"
#include "mongo/util/concurrency/mutex.h"
namespace mongo {
diff --git a/src/mongo/util/destructor_guard.h b/src/mongo/util/destructor_guard.h
new file mode 100644
index 00000000000..388cdb45668
--- /dev/null
+++ b/src/mongo/util/destructor_guard.h
@@ -0,0 +1,50 @@
+/** Copyright 2009 10gen Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects
+ * for all of the code used other than as permitted herein. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you do not
+ * wish to do so, delete this exception statement from your version. If you
+ * delete this exception statement from all source files in the program,
+ * then also delete it in the license file.
+ */
+
+#pragma once
+
+#include "mongo/logger/log_severity.h"
+#include "mongo/logger/logger.h"
+#include "mongo/logger/logstream_builder.h"
+#include "mongo/util/assert_util.h"
+
+#define DESTRUCTOR_GUARD MONGO_DESTRUCTOR_GUARD
+#define MONGO_DESTRUCTOR_GUARD(expression) \
+ try { \
+ expression; \
+ } catch (const std::exception& e) { \
+ ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
+ ::mongo::getThreadName(), \
+ ::mongo::logger::LogSeverity::Log()) \
+ << "caught exception (" << e.what() << ") in destructor (" << __FUNCTION__ << ")" \
+ << std::endl; \
+ } catch (...) { \
+ ::mongo::logger::LogstreamBuilder(::mongo::logger::globalLogDomain(), \
+ ::mongo::getThreadName(), \
+ ::mongo::logger::LogSeverity::Log()) \
+ << "caught unknown exception in destructor (" << __FUNCTION__ << ")" << std::endl; \
+ }
diff --git a/src/mongo/util/duration.cpp b/src/mongo/util/duration.cpp
index ac0faf19394..e3a29e858dc 100644
--- a/src/mongo/util/duration.cpp
+++ b/src/mongo/util/duration.cpp
@@ -34,7 +34,6 @@
#include "mongo/bson/util/builder.h"
namespace mongo {
-namespace x {
namespace {
template <typename Stream>
Stream& streamPut(Stream& os, Nanoseconds ns) {
@@ -142,5 +141,4 @@ template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<Trivi
Minutes);
template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
Hours);
-} // namespace x
} // namespace mongo
diff --git a/src/mongo/util/duration.h b/src/mongo/util/duration.h
index ba4f15ec44e..6cf26b06421 100644
--- a/src/mongo/util/duration.h
+++ b/src/mongo/util/duration.h
@@ -27,13 +27,13 @@
#pragma once
-#include <chrono>
#include <cstdint>
#include <iosfwd>
#include <limits>
#include <ratio>
#include "mongo/platform/overflow_arithmetic.h"
+#include "mongo/stdx/chrono.h"
#include "mongo/stdx/type_traits.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/mongoutils/str.h"
@@ -43,8 +43,6 @@ namespace mongo {
template <typename Allocator>
class StringBuilderImpl;
-namespace x {
-
template <typename Period>
class Duration;
@@ -103,7 +101,7 @@ using HigherPrecisionDuration =
* so attempting to cast that value to Milliseconds will throw an exception.
*/
template <typename ToDuration, typename FromPeriod>
-ToDuration durationCast(const Duration<FromPeriod>& from) {
+ToDuration duration_cast(const Duration<FromPeriod>& from) {
using FromOverTo = std::ratio_divide<FromPeriod, typename ToDuration::period>;
if (ToDuration::template isHigherPrecisionThan<Duration<FromPeriod>>()) {
typename ToDuration::rep toCount;
@@ -115,6 +113,29 @@ ToDuration durationCast(const Duration<FromPeriod>& from) {
return ToDuration{from.count() / FromOverTo::den};
}
+template <typename ToDuration, typename FromRep, typename FromPeriod>
+inline ToDuration duration_cast(const stdx::chrono::duration<FromRep, FromPeriod>& d) {
+ return duration_cast<ToDuration>(Duration<FromPeriod>{d.count()});
+}
+
+/**
+ * Convenience method for reading the count of a duration with specified units.
+ *
+ * Use when logging or comparing to integers, to ensure that you're using
+ * the units you intend.
+ *
+ * E.g., log() << durationCount<Seconds>(some duration) << " seconds";
+ */
+template <typename DOut, typename DIn>
+inline long long durationCount(DIn d) {
+ return duration_cast<DOut>(d).count();
+}
+
+template <typename DOut, typename RepIn, typename PeriodIn>
+inline long long durationCount(const stdx::chrono::duration<RepIn, PeriodIn>& d) {
+ return durationCount<DOut>(Duration<PeriodIn>{d.count()});
+}
+
/**
* Type representing a duration using a 64-bit counter.
*
@@ -197,12 +218,14 @@ public:
template <typename Rep2>
constexpr explicit Duration(const Rep2& r)
: _count(r) {
- static_assert(std::is_integral<Rep2>::value && std::is_signed<Rep2>::value,
- "Durations must be constructed from values of signed integral type");
+ static_assert(std::is_integral<Rep2>::value &&
+ (std::is_signed<Rep2>::value || sizeof(Rep2) < sizeof(rep)),
+ "Durations must be constructed from values of integral type that are "
+ "representable as 64-bit signed integers");
}
/**
- * Constructs a higher-precision duration from a lower-precision one, as by durationCast.
+ * Constructs a higher-precision duration from a lower-precision one, as by duration_cast.
*
* Throws a UserException if "from" is out of the range of this duration type.
*
@@ -210,18 +233,23 @@ public:
* this constructor.
*/
template <typename FromPeriod>
- /*implicit*/ Duration(const Duration<FromPeriod>& from) : Duration(durationCast<Duration>(from)) {
+ /*implicit*/ Duration(const Duration<FromPeriod>& from)
+ : Duration(duration_cast<Duration>(from)) {
static_assert(!isLowerPrecisionThan<Duration<FromPeriod>>(),
"Use duration_cast to convert from higher precision Duration types to lower "
"precision ones");
}
- constexpr operator stdx::chrono::duration<int64_t, period>() const {
- return stdx::chrono::duration<int64_t, period>{_count};
+ stdx::chrono::system_clock::duration toSystemDuration() const {
+ using SystemDuration = stdx::chrono::system_clock::duration;
+ return SystemDuration{duration_cast<Duration<SystemDuration::period>>(*this).count()};
}
/**
* Returns the number of periods represented by this duration.
+ *
+ * It is better to use durationCount<DesiredDurationType>(value), since it makes the unit of the
+ * count clear at the call site.
*/
constexpr rep count() const {
return _count;
@@ -411,5 +439,4 @@ Duration<Period> operator/(Duration<Period> d, const Rep2& scale) {
return d;
}
-} // namespace x
} // namespace mongo
diff --git a/src/mongo/util/duration_test.cpp b/src/mongo/util/duration_test.cpp
index 8e463bcee76..0a5f8c95c2a 100644
--- a/src/mongo/util/duration_test.cpp
+++ b/src/mongo/util/duration_test.cpp
@@ -25,11 +25,11 @@
* then also delete it in the license file.
*/
+#include "mongo/stdx/chrono.h"
#include "mongo/util/duration.h"
#include "mongo/unittest/unittest.h"
namespace mongo {
-namespace x {
namespace {
// The DurationTestSameType Compare* tests server to check the implementation of the comparison
@@ -114,30 +114,35 @@ TEST(DurationComparisonDifferentTypes, CompareAtLimits) {
ASSERT_LT(Seconds::min(), Milliseconds::min());
ASSERT_LT(Milliseconds::min(),
- durationCast<Milliseconds>(durationCast<Seconds>(Milliseconds::min())));
+ duration_cast<Milliseconds>(duration_cast<Seconds>(Milliseconds::min())));
ASSERT_GT(Milliseconds::max(),
- durationCast<Milliseconds>(durationCast<Seconds>(Milliseconds::max())));
+ duration_cast<Milliseconds>(duration_cast<Seconds>(Milliseconds::max())));
}
TEST(DurationCast, NonTruncatingDurationCasts) {
- ASSERT_EQ(1, durationCast<Seconds>(Milliseconds{1000}).count());
- ASSERT_EQ(1000, durationCast<Milliseconds>(Seconds{1}).count());
+ ASSERT_EQ(1, duration_cast<Seconds>(Milliseconds{1000}).count());
+ ASSERT_EQ(1000, duration_cast<Milliseconds>(Seconds{1}).count());
ASSERT_EQ(1000, Milliseconds{Seconds{1}}.count());
- ASSERT_EQ(1053, durationCast<Milliseconds>(Milliseconds{1053}).count());
+ ASSERT_EQ(1053, duration_cast<Milliseconds>(Milliseconds{1053}).count());
}
TEST(DurationCast, TruncatingDurationCasts) {
- ASSERT_EQ(1, durationCast<Seconds>(Milliseconds{1600}).count());
- ASSERT_EQ(0, durationCast<Seconds>(Milliseconds{999}).count());
- ASSERT_EQ(-1, durationCast<Seconds>(Milliseconds{-1600}).count());
- ASSERT_EQ(0, durationCast<Seconds>(Milliseconds{-999}).count());
+ ASSERT_EQ(1, duration_cast<Seconds>(Milliseconds{1600}).count());
+ ASSERT_EQ(0, duration_cast<Seconds>(Milliseconds{999}).count());
+ ASSERT_EQ(-1, duration_cast<Seconds>(Milliseconds{-1600}).count());
+ ASSERT_EQ(0, duration_cast<Seconds>(Milliseconds{-999}).count());
}
TEST(DurationCast, OverflowingCastsThrow) {
ASSERT_THROWS_CODE(
- durationCast<Milliseconds>(Seconds::max()), UserException, ErrorCodes::DurationOverflow);
+ duration_cast<Milliseconds>(Seconds::max()), UserException, ErrorCodes::DurationOverflow);
ASSERT_THROWS_CODE(
- durationCast<Milliseconds>(Seconds::min()), UserException, ErrorCodes::DurationOverflow);
+ duration_cast<Milliseconds>(Seconds::min()), UserException, ErrorCodes::DurationOverflow);
+}
+
+TEST(DurationCast, ImplicitConversionToStdxDuration) {
+ auto standardMillis = Milliseconds{10}.toSystemDuration();
+ ASSERT_EQUALS(Milliseconds{10}, duration_cast<Milliseconds>(standardMillis));
}
TEST(DurationAssignment, DurationAssignment) {
@@ -215,5 +220,4 @@ TEST(DurationArithmetic, DivideOverflowThrows) {
}
} // namespace
-} // namespace x
} // namespace mongo
diff --git a/src/mongo/util/net/sock.h b/src/mongo/util/net/sock.h
index 6a815100561..1ef0381c1c8 100644
--- a/src/mongo/util/net/sock.h
+++ b/src/mongo/util/net/sock.h
@@ -45,6 +45,7 @@
#endif // not _WIN32
#include <cstdint>
+#include <memory>
#include <string>
#include <utility>
#include <vector>
diff --git a/src/mongo/util/ntservice.cpp b/src/mongo/util/ntservice.cpp
index 571614a14c9..43028bf50e0 100644
--- a/src/mongo/util/ntservice.cpp
+++ b/src/mongo/util/ntservice.cpp
@@ -547,7 +547,7 @@ static void serviceStop() {
const auto timeout = Milliseconds(kStopWaitHintMillis / 2);
// We periodically check if we are done exiting by polling at half of each wait interval
- while (exitedCleanly.wait_for(timeout) != stdx::future_status::ready) {
+ while (exitedCleanly.wait_for(timeout.toSystemDuration()) != stdx::future_status::ready) {
reportStatus(SERVICE_STOP_PENDING, kStopWaitHintMillis);
log() << "Service Stop is waiting for storage engine to finish shutdown";
}
diff --git a/src/mongo/util/processinfo.h b/src/mongo/util/processinfo.h
index 7d48fe31aea..b2e6fcf2852 100644
--- a/src/mongo/util/processinfo.h
+++ b/src/mongo/util/processinfo.h
@@ -35,6 +35,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/platform/process_id.h"
+#include "mongo/stdx/mutex.h"
#include "mongo/util/concurrency/mutex.h"
namespace mongo {
diff --git a/src/mongo/util/text.cpp b/src/mongo/util/text.cpp
index 24bc71cf059..edb5c1a50b9 100644
--- a/src/mongo/util/text.cpp
+++ b/src/mongo/util/text.cpp
@@ -27,11 +27,14 @@
* then also delete it in the license file.
*/
+#include "mongo/platform/basic.h"
+
#include "mongo/util/text.h"
#include <boost/integer_traits.hpp>
#include <errno.h>
#include <iostream>
+#include <memory>
#include <sstream>
#ifdef _WIN32
diff --git a/src/mongo/util/time_support.cpp b/src/mongo/util/time_support.cpp
index f443db0f3b4..b26e0a07361 100644
--- a/src/mongo/util/time_support.cpp
+++ b/src/mongo/util/time_support.cpp
@@ -57,61 +57,6 @@ extern "C" time_t timegm(struct tm* const tmp);
namespace mongo {
-namespace {
-template <typename Stream>
-Stream& streamPut(Stream& os, Microseconds us) {
- return os << us.count() << "\xce\xbcs";
-}
-
-template <typename Stream>
-Stream& streamPut(Stream& os, Milliseconds ms) {
- return os << ms.count() << "ms";
-}
-
-template <typename Stream>
-Stream& streamPut(Stream& os, Seconds s) {
- return os << s.count() << 's';
-}
-} // namespace
-
-std::ostream& operator<<(std::ostream& os, Microseconds us) {
- return streamPut(os, us);
-}
-
-std::ostream& operator<<(std::ostream& os, Milliseconds ms) {
- return streamPut(os, ms);
-}
-std::ostream& operator<<(std::ostream& os, Seconds s) {
- return streamPut(os, s);
-}
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Microseconds us) {
- return streamPut(os, us);
-}
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Milliseconds ms) {
- return streamPut(os, ms);
-}
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Seconds s) {
- return streamPut(os, s);
-}
-
-template StringBuilderImpl<StackAllocator>& operator<<(StringBuilderImpl<StackAllocator>&,
- Microseconds);
-template StringBuilderImpl<StackAllocator>& operator<<(StringBuilderImpl<StackAllocator>&,
- Milliseconds);
-template StringBuilderImpl<StackAllocator>& operator<<(StringBuilderImpl<StackAllocator>&, Seconds);
-template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
- Microseconds);
-template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
- Milliseconds);
-template StringBuilderImpl<TrivialAllocator>& operator<<(StringBuilderImpl<TrivialAllocator>&,
- Seconds);
-
Date_t Date_t::max() {
return fromMillisSinceEpoch(std::numeric_limits<long long>::max());
}
@@ -124,7 +69,7 @@ Date_t::Date_t(stdx::chrono::system_clock::time_point tp)
: millis(durationCount<Milliseconds>(tp - stdx::chrono::system_clock::from_time_t(0))) {}
stdx::chrono::system_clock::time_point Date_t::toSystemTimePoint() const {
- return stdx::chrono::system_clock::from_time_t(0) + toDurationSinceEpoch();
+ return stdx::chrono::system_clock::from_time_t(0) + toDurationSinceEpoch().toSystemDuration();
}
bool Date_t::isFormattable() const {
@@ -773,14 +718,14 @@ bool toPointInTime(const string& str, boost::posix_time::ptime* timeOfDay) {
}
void sleepsecs(int s) {
- stdx::this_thread::sleep_for(Seconds(s));
+ stdx::this_thread::sleep_for(Seconds(s).toSystemDuration());
}
void sleepmillis(long long s) {
- stdx::this_thread::sleep_for(Milliseconds(s));
+ stdx::this_thread::sleep_for(Milliseconds(s).toSystemDuration());
}
void sleepmicros(long long s) {
- stdx::this_thread::sleep_for(Microseconds(s));
+ stdx::this_thread::sleep_for(Microseconds(s).toSystemDuration());
}
void Backoff::nextSleepMillis() {
diff --git a/src/mongo/util/time_support.h b/src/mongo/util/time_support.h
index 6f20025d832..a445e9b6f47 100644
--- a/src/mongo/util/time_support.h
+++ b/src/mongo/util/time_support.h
@@ -37,55 +37,17 @@
#include "mongo/base/status_with.h"
#include "mongo/stdx/chrono.h"
+#include "mongo/stdx/mutex.h"
+#include "mongo/util/duration.h"
namespace mongo {
template <typename Allocator>
class StringBuilderImpl;
-using Microseconds = stdx::chrono::microseconds;
-using Milliseconds = stdx::chrono::milliseconds;
-using Seconds = stdx::chrono::seconds;
-using Minutes = stdx::chrono::minutes;
-using Hours = stdx::chrono::hours;
-using stdx::chrono::duration_cast;
-
void time_t_to_Struct(time_t t, struct tm* buf, bool local = false);
std::string time_t_to_String_short(time_t t);
-//
-// Operators for putting durations to streams. Note that these will
-// *not* normally be found by ADL since the duration types are
-// typedefs, but see the handling of chrono::duration in
-// logstream_builder.h for why they are useful.
-//
-
-std::ostream& operator<<(std::ostream& os, Microseconds us);
-std::ostream& operator<<(std::ostream& os, Milliseconds ms);
-std::ostream& operator<<(std::ostream& os, Seconds s);
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Microseconds us);
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Milliseconds ms);
-
-template <typename Allocator>
-StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, Seconds s);
-
-/**
- * Convenience method for reading the count of a duration with specified units.
- *
- * Use when logging or comparing to integers, to ensure that you're using
- * the units you intend.
- *
- * E.g., log() << durationCount<Seconds>(some duration) << " seconds";
- */
-template <typename DOut, typename DIn>
-long long durationCount(DIn d) {
- return duration_cast<DOut>(d).count();
-}
-
/**
* Representation of a point in time, with millisecond resolution and capable
* of representing all times representable by the BSON Date type.
diff --git a/src/mongo/util/time_support_test.cpp b/src/mongo/util/time_support_test.cpp
index 64a6b3b16bf..24052f3f147 100644
--- a/src/mongo/util/time_support_test.cpp
+++ b/src/mongo/util/time_support_test.cpp
@@ -825,8 +825,8 @@ TEST(SystemTime, ConvertDateToSystemTime) {
const Date_t aDate = unittest::assertGet(dateFromISOString(isoTimeString));
const auto aTimePoint = aDate.toSystemTimePoint();
const auto actual = aTimePoint - stdx::chrono::system_clock::from_time_t(0);
- ASSERT(aDate.toDurationSinceEpoch() == actual) << "Expected " << aDate << "; but found "
- << Date_t::fromDurationSinceEpoch(actual);
+ ASSERT(aDate.toDurationSinceEpoch().toSystemDuration() == actual)
+ << "Expected " << aDate << "; but found " << Date_t::fromDurationSinceEpoch(actual);
ASSERT_EQUALS(aDate, Date_t(aTimePoint));
}