summaryrefslogtreecommitdiffstats
path: root/sysutils/hal/files/patch-hald_freebsd_clock
blob: 488283e02e366e910f96fbff8ebf613376cc0d73 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
--- hald/freebsd/libprobe/hfp.c.orig    2008-03-17 17:25:17.000000000 -0400
+++ hald/freebsd/libprobe/hfp.c 2008-03-26 12:07:32.000000000 -0400
@@ -216,55 +216,59 @@ hfp_getenv_bool (const char *variable)
 }
 
 void
-hfp_gettimeofday (struct timeval *t)
+hfp_clock_gettime (struct timespec *t)
 {
   int status;
 
   assert(t != NULL);
 
-  status = gettimeofday(t, NULL);
+#ifdef CLOCK_MONOTONIC_FAST
+  status = clock_gettime(CLOCK_MONOTONIC_FAST, t);
+#else
+  status = clock_gettime(CLOCK_MONOTONIC, t);
+#endif
   assert(status == 0);
 }
 
-/* timeval functions from sys/kern/kern_time.c */
+/* timespec functions from sys/kern/kern_time.c */
 
 static void
-hfp_timevalfix (struct timeval *t)
+hfp_timespecfix (struct timespec *t)
 {
   assert(t != NULL);
 
-  if (t->tv_usec < 0)
+  if (t->tv_nsec < 0)
     {
       t->tv_sec--;
-      t->tv_usec += 1000000;
+      t->tv_nsec += 1000000000;
     }
-  if (t->tv_usec >= 1000000)
+  if (t->tv_nsec >= 1000000000)
     {
       t->tv_sec++;
-      t->tv_usec -= 1000000;
+      t->tv_nsec -= 1000000000;
     }
 }
 
 void
-hfp_timevaladd (struct timeval *t1, const struct timeval *t2)
+hfp_timespecadd (struct timespec *t1, const struct timespec *t2)
 {
   assert(t1 != NULL);
   assert(t2 != NULL);
 
   t1->tv_sec += t2->tv_sec;
-  t1->tv_usec += t2->tv_usec;
+  t1->tv_nsec += t2->tv_nsec;
 
-  hfp_timevalfix(t1);
+  hfp_timespecfix(t1);
 }
 
 void
-hfp_timevalsub (struct timeval *t1, const struct timeval *t2)
+hfp_timespecsub (struct timespec *t1, const struct timespec *t2)
 {
   assert(t1 != NULL);
   assert(t2 != NULL);
 
   t1->tv_sec -= t2->tv_sec;
-  t1->tv_usec -= t2->tv_usec;
+  t1->tv_nsec -= t2->tv_nsec;
 
-  hfp_timevalfix(t1);
+  hfp_timespecfix(t1);
 }
--- hald/freebsd/libprobe/hfp.h.orig    2008-03-17 17:25:17.000000000 -0400
+++ hald/freebsd/libprobe/hfp.h 2008-04-02 14:35:50.000000000 -0400
@@ -29,8 +29,12 @@
 #endif
 
 #include <stdarg.h>
+#include <time.h>
 #include <sys/types.h>
+#include <sys/param.h>
+#if __FreeBSD_version < 600000
 #include <sys/time.h>
+#endif
 
 #include "libhal/libhal.h"
 
@@ -84,14 +88,14 @@ void volume_id_log (const char *format, 
 
 boolean hfp_getenv_bool (const char *variable);
 
-void hfp_gettimeofday (struct timeval *t);
-void hfp_timevaladd (struct timeval *t1, const struct timeval *t2);
-void hfp_timevalsub (struct timeval *t1, const struct timeval *t2);
+void hfp_clock_gettime (struct timespec *t);
+void hfp_timespecadd (struct timespec *t1, const struct timespec *t2);
+void hfp_timespecsub (struct timespec *t1, const struct timespec *t2);
 
 /* from sys/time.h (_KERNEL) */
-#define hfp_timevalcmp(t1, t2, cmp) \
+#define hfp_timespeccmp(t1, t2, cmp) \
   (((t1)->tv_sec == (t2)->tv_sec   \
-    ? ((t1)->tv_usec cmp (t2)->tv_usec)    \
+    ? ((t1)->tv_nsec cmp (t2)->tv_nsec)    \
     : ((t1)->tv_sec cmp (t2)->tv_sec)))
 
 #endif /* _HFP_H */