+\r
+{$ifdef unix}\r
+{$ifdef linux}{$define have_clock_gettime}{$endif}\r
+{$ifdef freebsd}{$define have_clock_gettime}{$endif}\r
+\r
+procedure gettimemonotonic(var tv:ttimeval);\r
+var\r
+ ts:ttimespec;\r
+begin\r
+ {$ifdef have_clock_gettime}\r
+ if (clock_gettime(CLOCK_MONOTONIC, @ts) = 0) then begin\r
+ tv.tv_sec := ts.tv_sec;\r
+ tv.tv_usec := ts.tv_nsec div 1000;\r
+ exit;\r
+ end;\r
+ {$endif}\r
+ gettimeofday(tv);\r
+end;\r
+{$endif}\r
+\r
+end.\r