Blender  V3.3
time.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include "PIL_time.h"
9 
10 #ifdef WIN32
11 # define WIN32_LEAN_AND_MEAN
12 # include <windows.h>
13 
14 double PIL_check_seconds_timer(void)
15 {
16  static int hasperfcounter = -1; /* (-1 == unknown) */
17  static double perffreq;
18 
19  if (hasperfcounter == -1) {
20  __int64 ifreq;
21  hasperfcounter = QueryPerformanceFrequency((LARGE_INTEGER *)&ifreq);
22  perffreq = (double)ifreq;
23  }
24 
25  if (hasperfcounter) {
26  __int64 count;
27 
28  QueryPerformanceCounter((LARGE_INTEGER *)&count);
29 
30  return count / perffreq;
31  }
32  else {
33  static double accum = 0.0;
34  static int ltick = 0;
35  int ntick = GetTickCount();
36 
37  if (ntick < ltick) {
38  accum += (0xFFFFFFFF - ltick + ntick) / 1000.0;
39  }
40  else {
41  accum += (ntick - ltick) / 1000.0;
42  }
43 
44  ltick = ntick;
45  return accum;
46  }
47 }
48 
49 long int PIL_check_seconds_timer_i(void)
50 {
51  return (long int)PIL_check_seconds_timer();
52 }
53 
54 void PIL_sleep_ms(int ms)
55 {
56  Sleep(ms);
57 }
58 
59 #else
60 
61 # include <sys/time.h>
62 # include <unistd.h>
63 
65 {
66  struct timeval tv;
67  struct timezone tz;
68 
69  gettimeofday(&tv, &tz);
70 
71  return ((double)tv.tv_sec + tv.tv_usec / 1000000.0);
72 }
73 
75 {
76  struct timeval tv;
77  struct timezone tz;
78 
79  gettimeofday(&tv, &tz);
80 
81  return tv.tv_sec;
82 }
83 
84 void PIL_sleep_ms(int ms)
85 {
86  if (ms >= 1000) {
87  sleep(ms / 1000);
88  ms = (ms % 1000);
89  }
90 
91  usleep(ms * 1000);
92 }
93 
94 #endif
typedef double(DMatrix)[4][4]
Platform independent time functions.
int count
void PIL_sleep_ms(int ms)
Definition: time.c:84
double PIL_check_seconds_timer(void)
Definition: time.c:64
long int PIL_check_seconds_timer_i(void)
Definition: time.c:74