summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2017-08-15 23:22:36 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2017-09-15 14:22:51 +0200
commit73bc364347fc8325a632f17fcda220ce7d6f5945 (patch)
treefd2ee517f8d15d3c5ffe2ef044aed12df89f9b47 /tools
parentcef9cf59f8064be99ce3b7d0738ab0775715112c (diff)
Add tools::Time::GetMonotonicTicks (us)
This moves a combination of tools::Time::GetSystemTicks(), canvas ElapsedTime::getSystemTime() and the opencl timing implementation into tools::Time::GetMonotonicTicks() as a monotonic microsecond time source. Change-Id: I5c9263540b8af55b2eeca6126e288129427f6e8e Reviewed-on: https://gerrit.libreoffice.org/41991 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/Library_tl.mk1
-rw-r--r--tools/source/datetime/ttime.cxx66
2 files changed, 47 insertions, 20 deletions
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk
index 040490ed7f05..f82338d746cf 100644
--- a/tools/Library_tl.mk
+++ b/tools/Library_tl.mk
@@ -107,6 +107,7 @@ $(eval $(call gb_Library_use_system_win32_libs,tl,\
ole32 \
shell32 \
uuid \
+ winmm \
))
endif
diff --git a/tools/source/datetime/ttime.cxx b/tools/source/datetime/ttime.cxx
index 83812f72171a..4f469906118e 100644
--- a/tools/source/datetime/ttime.cxx
+++ b/tools/source/datetime/ttime.cxx
@@ -23,6 +23,7 @@
#if defined(_WIN32)
#include <windows.h>
+#include <mmsystem.h>
#elif defined UNX
#include <unistd.h>
#include <limits.h>
@@ -34,6 +35,7 @@
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
+#include <mach/mach_time.h>
#endif
#include <sal/log.hxx>
@@ -411,30 +413,54 @@ Time tools::Time::GetUTCOffset()
sal_uInt64 tools::Time::GetSystemTicks()
{
-#if defined(_WIN32)
- static LARGE_INTEGER nTicksPerSecond;
- static bool bTicksPerSecondInitialized = false;
- if (!bTicksPerSecondInitialized)
- {
- QueryPerformanceFrequency(&nTicksPerSecond);
- bTicksPerSecondInitialized = true;
- }
+ return tools::Time::GetMonotonicTicks() / 1000;
+}
- LARGE_INTEGER nPerformanceCount;
- QueryPerformanceCounter(&nPerformanceCount);
+#ifdef _WIN32
+static LARGE_INTEGER initPerformanceFrequency()
+{
+ LARGE_INTEGER nTicksPerSecond = { 0 };
+ if (!QueryPerformanceFrequency(&nTicksPerSecond))
+ nTicksPerSecond.QuadPart = 0;
+ return nTicksPerSecond;
+}
+#endif
- return static_cast<sal_uInt64>(
- (nPerformanceCount.QuadPart*1000)/nTicksPerSecond.QuadPart);
-#else
- timeval tv;
- int n = gettimeofday (&tv, nullptr);
- if (n == -1) {
- int e = errno;
- SAL_WARN("tools.datetime", "gettimeofday failed: " << e);
+sal_uInt64 tools::Time::GetMonotonicTicks()
+{
+#ifdef _WIN32
+ static const LARGE_INTEGER nTicksPerSecond = initPerformanceFrequency();
+ if (nTicksPerSecond.QuadPart > 0)
+ {
+ LARGE_INTEGER nPerformanceCount;
+ QueryPerformanceCounter(&nPerformanceCount);
+ return static_cast<sal_uInt64>(
+ ( nPerformanceCount.QuadPart * 1000 * 1000 ) / nTicksPerSecond.QuadPart );
}
- return static_cast<sal_uInt64>(tv.tv_sec) * 1000
- + static_cast<sal_uInt64>(tv.tv_usec) / 1000;
+ else
+ {
+ return static_cast<sal_uInt64>( timeGetTime() * 1000 );
+ }
+#else
+ sal_uInt64 nMicroSeconds;
+#ifdef __MACH__
+ static mach_timebase_info_data_t info = { 0, 0 };
+ if ( 0 == info.numer )
+ mach_timebase_info( &info );
+ nMicroSeconds = mach_absolute_time() * (double) (info.numer / info.denom) / 1000;
+#else
+#if defined(USE_CLOCK_GETTIME)
+ struct timespec currentTime;
+ clock_gettime( CLOCK_MONOTONIC, &currentTime );
+ nMicroSeconds = currentTime.tv_sec * 1000 * 1000 + currentTime.tv_nsec / 1000;
+#else
+ struct timeval currentTime;
+ gettimeofday( &currentTime, nullptr );
+ nMicroSeconds = currentTime.tv_sec * 1000 * 1000 + currentTime.tv_usec;
#endif
+#endif // __MACH__
+ return nMicroSeconds;
+#endif // _WIN32
}
} /* namespace tools */
95 100644
--- a/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx
+++ b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx
@@ -1021,7 +1021,7 @@ xmlSecKeysMngrPtr SecurityEnvironment_MSCryptImpl::createKeysManager() {
/*-
* The following lines is based on the of xmlsec-mscrypto crypto engine
*/
- pKeysMngr = xmlSecMSCryptoAppliedKeysMngrCreate() ;
+ pKeysMngr = xmlsecurity::MSCryptoAppliedKeysMngrCreate() ;
if( pKeysMngr == nullptr )
throw uno::RuntimeException() ;
@@ -1032,7 +1032,7 @@ xmlSecKeysMngrPtr SecurityEnvironment_MSCryptImpl::createKeysManager() {
//Add system key store into the keys manager.
m_hMySystemStore = CertOpenSystemStoreW( 0, L"MY" ) ;
if( m_hMySystemStore != nullptr ) {
- if( xmlSecMSCryptoAppliedKeysMngrAdoptKeyStore( pKeysMngr, m_hMySystemStore ) < 0 ) {
+ if( xmlsecurity::MSCryptoAppliedKeysMngrAdoptKeyStore( pKeysMngr, m_hMySystemStore ) < 0 ) {
CertCloseStore( m_hMySystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
m_hMySystemStore = nullptr;
throw uno::RuntimeException() ;
@@ -1042,7 +1042,7 @@ xmlSecKeysMngrPtr SecurityEnvironment_MSCryptImpl::createKeysManager() {
//Add system root store into the keys manager.
m_hRootSystemStore = CertOpenSystemStoreW( 0, L"Root" ) ;
if( m_hRootSystemStore != nullptr ) {
- if( xmlSecMSCryptoAppliedKeysMngrAdoptTrustedStore( pKeysMngr, m_hRootSystemStore ) < 0 ) {
+ if( xmlsecurity::MSCryptoAppliedKeysMngrAdoptTrustedStore( pKeysMngr, m_hRootSystemStore ) < 0 ) {
CertCloseStore( m_hRootSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
m_hRootSystemStore = nullptr;
throw uno::RuntimeException() ;
@@ -1052,7 +1052,7 @@ xmlSecKeysMngrPtr SecurityEnvironment_MSCryptImpl::createKeysManager() {
//Add system trusted store into the keys manager.
m_hTrustSystemStore = CertOpenSystemStoreW( 0, L"Trust" ) ;
if( m_hTrustSystemStore != nullptr ) {
- if( xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore( pKeysMngr, m_hTrustSystemStore ) < 0 ) {
+ if( xmlsecurity::MSCryptoAppliedKeysMngrAdoptUntrustedStore( pKeysMngr, m_hTrustSystemStore ) < 0 ) {
CertCloseStore( m_hTrustSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
m_hTrustSystemStore = nullptr;
throw uno::RuntimeException() ;
@@ -1062,7 +1062,7 @@ xmlSecKeysMngrPtr SecurityEnvironment_MSCryptImpl::createKeysManager() {
//Add system CA store into the keys manager.
m_hCaSystemStore = CertOpenSystemStoreW( 0, L"CA" ) ;
if( m_hCaSystemStore != nullptr ) {
- if( xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore( pKeysMngr, m_hCaSystemStore ) < 0 ) {
+ if( xmlsecurity::MSCryptoAppliedKeysMngrAdoptUntrustedStore( pKeysMngr, m_hCaSystemStore ) < 0 ) {
CertCloseStore( m_hCaSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
m_hCaSystemStore = nullptr;
throw uno::RuntimeException() ;