Debian Codegraph @

ulib/gettime.c

raw
1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4
5 #include "ulib/gettime.h"
6
7 #ifdef __cplusplus
8 }
9 #endif
10
11
12 void (*uu_gettime_U2time)(pTHX_ UV ret[2]);
13
14 /* called at boot */
15 void uu_gettime_init(pUCXT) {
16 SV **svp;
17 require_pv("Time/HiRes.pm");
18 svp = hv_fetchs(PL_modglobal, "Time::U2time", 0);
19 if (!svp) croak("Time::HiRes is required");
20 if (!SvIOK(*svp)) croak("Time::U2time isn't a function pointer");
21 uu_gettime_U2time = INT2PTR(void(*)(pTHX_ UV ret[2]), SvIV(*svp));
22 /*
23 if (0) {
24 UV xx[2];
25 (*uu_gettime_U2time)(aTHX_ xx);
26 printf("The current seconds are: %" UVuf ".%06" UVuf "\n", xx[0], xx[1]);
27 exit(0);
28 }
29 */
30 }
31
32 U64 uu_gettime_100ns64(pUCXT) {
33 struct timeval tv;
34 U64 rv;
35 UV ptod[2];
36
37 /* gettimeofday(&tv, 0); */
38 (*uu_gettime_U2time)(aTHX_ ptod);
39 tv.tv_sec = (long)ptod[0];
40 tv.tv_usec = (long)ptod[1];
41
42 rv = tv.tv_sec * 10000000 + tv.tv_usec * 10;
43 return rv;
44 }
45
46 /* ex:set ts=2 sw=2 itab=spaces: */