summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2020-08-22 05:56:05 +0000
committerStefan Schmidt <stefan@datenfreihafen.org>2020-08-31 14:24:05 +0200
commit33304d656cf5a1b4580ce711851c3ebc57f1acea (patch)
tree8f56b9505d3035bf83ed490181f776a8e507ce05
parent45cabae42b766a9c5df1f577ca251d04f90bbdff (diff)
Ecore: more precise implementation of ecore_time_get on Windows
Implement directly monotonic clock on Windows, to have more accurate results Reviewed-by: João Paulo Taylor Ienczak Zanette <joao.tiz@expertisesolutions.com.br> Reviewed-by: Stefan Schmidt <stefan@datenfreihafen.org> Differential Revision: https://phab.enlightenment.org/D12112
-rw-r--r--src/lib/ecore/ecore_time.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/lib/ecore/ecore_time.c b/src/lib/ecore/ecore_time.c
index f2afe0e860..9f039e2b59 100644
--- a/src/lib/ecore/ecore_time.c
+++ b/src/lib/ecore/ecore_time.c
@@ -13,10 +13,16 @@
13 13
14#include <time.h> 14#include <time.h>
15 15
16#ifdef _WIN32
17# include <evil_private.h> /* gettimeofday */
18#endif
19
16#include "Ecore.h" 20#include "Ecore.h"
17#include "ecore_private.h" 21#include "ecore_private.h"
18 22
19#if defined (HAVE_CLOCK_GETTIME) 23#if defined(_WIN32)
24static LONGLONG _ecore_time_freq;
25#elif defined (HAVE_CLOCK_GETTIME)
20static clockid_t _ecore_time_clock_id; 26static clockid_t _ecore_time_clock_id;
21static Eina_Bool _ecore_time_got_clock_id = EINA_FALSE; 27static Eina_Bool _ecore_time_got_clock_id = EINA_FALSE;
22#elif defined(__APPLE__) && defined(__MACH__) 28#elif defined(__APPLE__) && defined(__MACH__)
@@ -26,7 +32,12 @@ static double _ecore_time_clock_conversion = 1e-9;
26EAPI double 32EAPI double
27ecore_time_get(void) 33ecore_time_get(void)
28{ 34{
29#if defined (HAVE_CLOCK_GETTIME) 35#ifdef _WIN32
36 LARGE_INTEGER count;
37
38 QueryPerformanceCounter(&count);
39 return (double)count.QuadPart/ (double)_ecore_time_freq;
40#elif defined (HAVE_CLOCK_GETTIME)
30 struct timespec t; 41 struct timespec t;
31 42
32 if (EINA_UNLIKELY(!_ecore_time_got_clock_id)) 43 if (EINA_UNLIKELY(!_ecore_time_got_clock_id))
@@ -39,8 +50,6 @@ ecore_time_get(void)
39 } 50 }
40 51
41 return (double)t.tv_sec + (((double)t.tv_nsec) / 1000000000.0); 52 return (double)t.tv_sec + (((double)t.tv_nsec) / 1000000000.0);
42#elif defined(_WIN32)
43 return evil_time_get();
44#elif defined(__APPLE__) && defined(__MACH__) 53#elif defined(__APPLE__) && defined(__MACH__)
45 return _ecore_time_clock_conversion * (double)mach_absolute_time(); 54 return _ecore_time_clock_conversion * (double)mach_absolute_time();
46#else 55#else
@@ -82,7 +91,12 @@ ecore_loop_time_set(double t)
82void 91void
83_ecore_time_init(void) 92_ecore_time_init(void)
84{ 93{
85#if defined(HAVE_CLOCK_GETTIME) 94#if defined(_WIN32)
95 LARGE_INTEGER freq;
96
97 QueryPerformanceFrequency(&freq);
98 _ecore_time_freq = freq.QuadPart;
99#elif defined(HAVE_CLOCK_GETTIME)
86 struct timespec t; 100 struct timespec t;
87 101
88 if (_ecore_time_got_clock_id) return; 102 if (_ecore_time_got_clock_id) return;
@@ -103,18 +117,16 @@ _ecore_time_init(void)
103 else 117 else
104 CRI("Cannot get a valid clock_gettime() clock id! Fallback to unix time"); 118 CRI("Cannot get a valid clock_gettime() clock id! Fallback to unix time");
105#else 119#else
106# ifndef _WIN32 120# if defined(__APPLE__) && defined(__MACH__)
107# if defined(__APPLE__) && defined(__MACH__)
108 mach_timebase_info_data_t info; 121 mach_timebase_info_data_t info;
109 kern_return_t err = mach_timebase_info(&info); 122 kern_return_t err = mach_timebase_info(&info);
110 if (err == 0) 123 if (err == 0)
111   _ecore_time_clock_conversion = 1e-9 * (double)info.numer / (double)info.denom; 124   _ecore_time_clock_conversion = 1e-9 * (double)info.numer / (double)info.denom;
112 else 125 else
113 WRN("Unable to get timebase info. Fallback to nanoseconds"); 126 WRN("Unable to get timebase info. Fallback to nanoseconds");
114# else 127# else
115# warning "Your platform isn't supported yet" 128# warning "Your platform isn't supported yet"
116 CRI("Platform does not support clock_gettime. Fallback to unix time"); 129 CRI("Platform does not support clock_gettime. Fallback to unix time");
117# endif
118# endif 130# endif
119#endif 131#endif
120 ecore_loop_time_set(ecore_time_get()); 132 ecore_loop_time_set(ecore_time_get());