platform.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OpenKinect Project. http://www.openkinect.org
3  *
4  * Copyright (c) 2010 Brandyn White (bwhite@dappervision.com)
5  *
6  * This code is licensed to you under the terms of the Apache License, version
7  * 2.0, or, at your option, the terms of the GNU General Public License,
8  * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
9  * or the following URLs:
10  * http://www.apache.org/licenses/LICENSE-2.0
11  * http://www.gnu.org/licenses/gpl-2.0.txt
12  *
13  * If you redistribute this file in source form, modified or unmodified, you
14  * may:
15  * 1) Leave this header intact and distribute it under the same terms,
16  * accompanying it with the APACHE20 and GPL20 files, or
17  * 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
18  * 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
19  * In all cases you must keep the copyright notice intact and include a copy
20  * of the CONTRIB file.
21  *
22  * Binary distributions must follow the binary distribution requirements of
23  * either License.
24  */
25 #pragma once
26 
27 #include <math.h>
28 #ifdef _WIN32
29  #include <direct.h>
30  #include <windows.h>
31  #define snprintf _snprintf
32  #define popen _popen
33 #else
34  #include <time.h>
35  #include <unistd.h>
36 #endif
37 
38 
39 double get_time()
40 {
41 #ifdef _WIN32
42  SYSTEMTIME st;
43  GetSystemTime(&st);
44  FILETIME ft;
45  SystemTimeToFileTime(&st, &ft);
46  ULARGE_INTEGER li;
47  li.LowPart = ft.dwLowDateTime;
48  li.HighPart = ft.dwHighDateTime;
49  // FILETIME is given as a 64-bit value for the number of 100-nanosecond
50  // intervals that have passed since Jan 1, 1601 (UTC). The difference between that
51  // epoch and the POSIX epoch (Jan 1, 1970) is 116444736000000000 such ticks.
52  uint64_t total_usecs = (li.QuadPart - 116444736000000000L) / 10L;
53  return (total_usecs / 1000000.);
54 #else
55  struct timeval cur;
56  gettimeofday(&cur, NULL);
57  return cur.tv_sec + cur.tv_usec / 1000000.;
58 #endif
59 }
60 
61 void sleep_highres(double tm)
62 {
63 #ifdef _WIN32
64  int msec = floor(tm * 1000);
65  if (msec > 0) {
66  Sleep(msec);
67  }
68 #else
69  int sec = floor(tm);
70  int usec = (tm - sec) * 1000000;
71  if (tm > 0) {
72  sleep(sec);
73  usleep(usec);
74  }
75 #endif
76 }
void sleep_highres(double tm)
Definition: platform.h:61
unsigned __int64 uint64_t
double get_time()
Definition: platform.h:39


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Mon Jun 10 2019 13:46:42