| 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 |
204 |
| void uu_gettime_init(pUCXT) { |
| 16 |
|
| SV **svp; |
| 17 |
204 |
| require_pv("Time/HiRes.pm"); |
| 18 |
204 |
| svp = hv_fetchs(PL_modglobal, "Time::U2time", 0); |
| 19 |
204 |
▶ | if (!svp) croak("Time::HiRes is required"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!svp) croak("Time::HiRes is required"); |
0 |
204 |
204 |
|
| 20 |
204 |
▶ | if (!SvIOK(*svp)) croak("Time::U2time isn't a function pointer"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvIOK(*svp)) croak("Time::U2time isn't a function pointer"); |
0 |
204 |
204 |
|
| 21 |
204 |
| 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 |
204 |
| } |
| 31 |
|
| |
| 32 |
0 |
| U64 uu_gettime_100ns64(pUCXT) { |
| 33 |
|
| struct timeval tv; |
| 34 |
|
| U64 rv; |
| 35 |
|
| UV ptod[2]; |
| 36 |
|
| |
| 37 |
|
| /* gettimeofday(&tv, 0); */ |
| 38 |
0 |
| (*uu_gettime_U2time)(aTHX_ ptod); |
| 39 |
0 |
| tv.tv_sec = (long)ptod[0]; |
| 40 |
0 |
| tv.tv_usec = (long)ptod[1]; |
| 41 |
|
| |
| 42 |
0 |
| rv = tv.tv_sec * 10000000 + tv.tv_usec * 10; |
| 43 |
0 |
| return rv; |
| 44 |
|
| } |
| 45 |
|
| |
| 46 |
|
| /* ex:set ts=2 sw=2 itab=spaces: */ |