Last change
on this file since 28 was
2,
checked in by Sam Hocevar, 18 years ago
|
- imported original 0.7.0 tarball
|
File size:
919 bytes
|
Line | |
---|
1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <sys/time.h> |
---|
4 | #include <time.h> |
---|
5 | #include "timing.hpp" |
---|
6 | |
---|
7 | #ifdef __APPLE__ |
---|
8 | // OSX 10.1 has nanosleep but no header for it! |
---|
9 | extern "C" { |
---|
10 | int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); |
---|
11 | } |
---|
12 | #endif |
---|
13 | |
---|
14 | // Constructor |
---|
15 | // |
---|
16 | time_marker::time_marker() |
---|
17 | { |
---|
18 | get_time(); |
---|
19 | } |
---|
20 | |
---|
21 | // |
---|
22 | // get_time() |
---|
23 | // Get the current time |
---|
24 | // |
---|
25 | void time_marker::get_time() |
---|
26 | { |
---|
27 | struct timeval tv = { 0, 0 }; |
---|
28 | gettimeofday( &tv, NULL ); |
---|
29 | seconds = tv.tv_sec; |
---|
30 | micro_seconds = tv.tv_usec; |
---|
31 | } |
---|
32 | |
---|
33 | // |
---|
34 | // diff_time() |
---|
35 | // Find the time difference |
---|
36 | // |
---|
37 | double time_marker::diff_time( time_marker *other ) |
---|
38 | { |
---|
39 | return (double)(seconds - other->seconds) + (double)(micro_seconds - other->micro_seconds) / 1000000; |
---|
40 | } |
---|
41 | |
---|
42 | void timer_init() |
---|
43 | { |
---|
44 | /* Do Nothing */ |
---|
45 | } |
---|
46 | |
---|
47 | void timer_uninit() |
---|
48 | { |
---|
49 | /* Do Nothing */ |
---|
50 | } |
---|
51 | |
---|
52 | void milli_wait( unsigned wait_time ) |
---|
53 | { |
---|
54 | struct timespec ts = { 0, wait_time * 1000000 }; |
---|
55 | nanosleep( &ts, NULL ); |
---|
56 | } |
---|
57 | |
---|
Note: See
TracBrowser
for help on using the repository browser.