aboutsummaryrefslogtreecommitdiffstats
path: root/src/chrono.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:16 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:16 +0000
commit1147845301c03308e3419b89c28c77bb6917fe04 (patch)
tree225f45e462607f9595a5e5f418a9533ab50e83bb /src/chrono.cpp
parentb7332b04df5d50c92640c74cfeb138ecb7e3f7ae (diff)
downloadsrc-1147845301c03308e3419b89c28c77bb6917fe04.tar.gz
src-1147845301c03308e3419b89c28c77bb6917fe04.zip
Vendor import of stripped libc++ trunk r366426 (just before the release_90 branchvendor/libc++/libc++-trunk-r366426
Notes
Notes: svn path=/vendor/libc++/dist/; revision=351284 svn path=/vendor/libc++/libc++-trunk-r366426/; revision=351285; tag=vendor/libc++/libc++-trunk-r366426
Diffstat (limited to 'src/chrono.cpp')
-rw-r--r--src/chrono.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/chrono.cpp b/src/chrono.cpp
index 882d50b9d731..8f533f1059ed 100644
--- a/src/chrono.cpp
+++ b/src/chrono.cpp
@@ -1,9 +1,8 @@
//===------------------------- chrono.cpp ---------------------------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -38,6 +37,10 @@
#endif
#endif
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
+#pragma comment(lib, "rt")
+#endif
+
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
@@ -178,16 +181,26 @@ steady_clock::now() _NOEXCEPT
#elif defined(_LIBCPP_WIN32API)
+// https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx says:
+// If the function fails, the return value is zero. <snip>
+// On systems that run Windows XP or later, the function will always succeed
+// and will thus never return zero.
+
+static LARGE_INTEGER
+__QueryPerformanceFrequency()
+{
+ LARGE_INTEGER val;
+ (void) QueryPerformanceFrequency(&val);
+ return val;
+}
+
steady_clock::time_point
steady_clock::now() _NOEXCEPT
{
- static LARGE_INTEGER freq;
- static BOOL initialized = FALSE;
- if (!initialized)
- initialized = QueryPerformanceFrequency(&freq); // always succceeds
+ static const LARGE_INTEGER freq = __QueryPerformanceFrequency();
LARGE_INTEGER counter;
- QueryPerformanceCounter(&counter);
+ (void) QueryPerformanceCounter(&counter);
return time_point(duration(counter.QuadPart * nano::den / freq.QuadPart));
}