DIY  3.0
data-parallel out-of-core C++ library
 All Classes Namespaces Functions Typedefs Groups Pages
time.hpp
1 #ifndef DIY_TIME_HPP
2 #define DIY_TIME_HPP
3 
4 #include <sys/time.h>
5 
6 #ifdef __MACH__
7 #include <mach/clock.h>
8 #include <mach/mach.h>
9 #endif
10 
11 namespace diy
12 {
13 
14 typedef unsigned long time_type;
15 
16 inline time_type get_time()
17 {
18 #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
19  clock_serv_t cclock;
20  mach_timespec_t ts;
21  host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
22  clock_get_time(cclock, &ts);
23  mach_port_deallocate(mach_task_self(), cclock);
24 #else
25  timespec ts;
26  clock_gettime(CLOCK_REALTIME, &ts);
27 #endif
28  return ts.tv_sec*1000 + ts.tv_nsec/1000000;
29 }
30 
31 }
32 
33 #endif