+{$ifdef linux}\r
+ {$define monotimefloat_implemented}\r
+ const\r
+ CLOCK_MONOTONIC = 1;\r
+ type \r
+ ptimeval = ^ttimeval;\r
+ tclock_gettime = function(clk_id: integer; tp: ptimeval): integer; cdecl;\r
+\r
+ var\r
+ librt_handle:pointer;\r
+ librt_inited:boolean;\r
+ clock_gettime: tclock_gettime;\r
+\r
+ function monotimefloat:float;\r
+ var\r
+ ts: ttimeval;\r
+ begin\r
+ if not librt_inited then begin\r
+ librt_inited := true;\r
+ clock_gettime := nil;\r
+ librt_handle := dlopen('librt.so', RTLD_LAZY);\r
+ if assigned(librt_handle) then begin\r
+ clock_gettime := dlsym(librt_handle, 'clock_gettime');\r
+ end;\r
+ end;\r
+ if assigned(clock_gettime) then begin\r
+ if clock_gettime(CLOCK_MONOTONIC, @ts) = 0 then begin\r
+ //note this really returns nanoseconds\r
+ result := ts.tv_sec + ts.tv_usec / 1000000000.0;\r
+ exit;\r
+ end;\r
+ end;\r
+ //fallback\r
+ result := unixtimefloat;\r
+ end;\r
+\r
+\r
+{$endif} {linux}\r
+\r
+{$ifdef darwin} {mac OS X}\r
+{$define monotimefloat_implemented}\r
+\r
+ type\r
+ tmach_timebase_info = packed record\r
+ numer: longint;\r
+ denom: longint;\r
+ end;\r
+ pmach_timebase_info = ^tmach_timebase_info;\r
+ \r
+ function mach_absolute_time: int64; cdecl; external;\r
+ function mach_timebase_info(info: pmach_timebase_info): integer; cdecl; external;\r
+\r
+ var\r
+ timebase_info: tmach_timebase_info;\r
+\r
+ function monotimefloat:float;\r
+ var\r
+ i:int64;\r
+ begin\r
+ if timebase_info.denom = 0 then begin\r
+ mach_timebase_info(@timebase_info);\r
+ end;\r
+ i := mach_absolute_time;\r
+ result := (i * timebase_info.numer div timebase_info.denom) / 1000000000.0;\r
+ end;\r
+\r
+{$endif} {darwin, mac OS X}\r
+\r