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