~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/util/os_time.c

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include "os_time.h"
36
36
#include "detect_os.h"
37
37
 
 
38
#include "c11/time.h"
 
39
 
38
40
#include "util/u_atomic.h"
39
41
 
40
42
#if DETECT_OS_UNIX
53
55
int64_t
54
56
os_time_get_nano(void)
55
57
{
56
 
#if DETECT_OS_LINUX || DETECT_OS_BSD
57
 
 
58
 
   struct timespec tv;
59
 
   clock_gettime(CLOCK_MONOTONIC, &tv);
60
 
   return tv.tv_nsec + tv.tv_sec*INT64_C(1000000000);
61
 
 
62
 
#elif DETECT_OS_UNIX
63
 
 
64
 
   struct timeval tv;
65
 
   gettimeofday(&tv, NULL);
66
 
   return tv.tv_usec*INT64_C(1000) + tv.tv_sec*INT64_C(1000000000);
67
 
 
68
 
#elif DETECT_OS_WINDOWS
69
 
 
70
 
   LARGE_INTEGER frequency;
71
 
   LARGE_INTEGER counter;
72
 
   int64_t secs, nanosecs;
73
 
   QueryPerformanceFrequency(&frequency);
74
 
   QueryPerformanceCounter(&counter);
75
 
   /* Compute seconds and nanoseconds parts separately to
76
 
    * reduce severity of precision loss.
77
 
    */
78
 
   secs = counter.QuadPart / frequency.QuadPart;
79
 
   nanosecs = (counter.QuadPart % frequency.QuadPart) * INT64_C(1000000000)
80
 
      / frequency.QuadPart;
81
 
   return secs*INT64_C(1000000000) + nanosecs;
82
 
 
83
 
#else
84
 
 
85
 
#error Unsupported OS
86
 
 
87
 
#endif
 
58
   struct timespec ts;
 
59
   timespec_get(&ts, TIME_MONOTONIC);
 
60
   return ts.tv_nsec + ts.tv_sec*INT64_C(1000000000);
88
61
}
89
62
 
90
63