Blender  V2.93
time.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include "PIL_time.h"
25 
26 #ifdef WIN32
27 # define WIN32_LEAN_AND_MEAN
28 # include <windows.h>
29 
30 double PIL_check_seconds_timer(void)
31 {
32  static int hasperfcounter = -1; /* (-1 == unknown) */
33  static double perffreq;
34 
35  if (hasperfcounter == -1) {
36  __int64 ifreq;
37  hasperfcounter = QueryPerformanceFrequency((LARGE_INTEGER *)&ifreq);
38  perffreq = (double)ifreq;
39  }
40 
41  if (hasperfcounter) {
42  __int64 count;
43 
44  QueryPerformanceCounter((LARGE_INTEGER *)&count);
45 
46  return count / perffreq;
47  }
48  else {
49  static double accum = 0.0;
50  static int ltick = 0;
51  int ntick = GetTickCount();
52 
53  if (ntick < ltick) {
54  accum += (0xFFFFFFFF - ltick + ntick) / 1000.0;
55  }
56  else {
57  accum += (ntick - ltick) / 1000.0;
58  }
59 
60  ltick = ntick;
61  return accum;
62  }
63 }
64 
65 long int PIL_check_seconds_timer_i(void)
66 {
67  return (long int)PIL_check_seconds_timer();
68 }
69 
70 void PIL_sleep_ms(int ms)
71 {
72  Sleep(ms);
73 }
74 
75 #else
76 
77 # include <sys/time.h>
78 # include <unistd.h>
79 
81 {
82  struct timeval tv;
83  struct timezone tz;
84 
85  gettimeofday(&tv, &tz);
86 
87  return ((double)tv.tv_sec + tv.tv_usec / 1000000.0);
88 }
89 
91 {
92  struct timeval tv;
93  struct timezone tz;
94 
95  gettimeofday(&tv, &tz);
96 
97  return tv.tv_sec;
98 }
99 
100 void PIL_sleep_ms(int ms)
101 {
102  if (ms >= 1000) {
103  sleep(ms / 1000);
104  ms = (ms % 1000);
105  }
106 
107  usleep(ms * 1000);
108 }
109 
110 #endif
typedef double(DMatrix)[4][4]
Platform independent time functions.
int count
void PIL_sleep_ms(int ms)
Definition: time.c:100
double PIL_check_seconds_timer(void)
Definition: time.c:80
long int PIL_check_seconds_timer_i(void)
Definition: time.c:90