result64: integer;\r
   tv : ttimeval;\r
 begin\r
-  gettimeofday(tv);\r
+  gettimemonotonic(tv);\r
   result64 := (tv.tv_sec*1000)+(tv.tv_usec div 1000);\r
   result := result64;\r
 end;\r
     threaddata := findthreaddata(tm.GetCurrentThreadId);\r
     if threaddata.lcorethread then raise exception.create('get/peek message cannot be used in the lcore thread');\r
     message := threaddata.messagequeue;\r
-    gettimeofday(nowtv);\r
+    gettimemonotonic(nowtv);\r
     while (not peek) and (message=nil) and (not tv_compare(nowtv,threaddata.nexttimer)) do begin\r
       threaddata.waiting := true;\r
       structurelock.release;\r
 \r
         timeouttv := threaddata.nexttimer;\r
         timeoutms := (timeouttv.tv_sec * 1000)+(timeouttv.tv_usec div 1000);\r
-        //i'm assuming the timeout is in milliseconds\r
+        //i am assuming the timeout is in milliseconds\r
         if (timeoutms > maxlongint) then timeoutms := maxlongint;\r
         threaddata.messageevent.waitfor(timeoutms);\r
 \r
       structurelock.acquire;\r
       threaddata.waiting := false;\r
       message := threaddata.messagequeue;\r
-      gettimeofday(nowtv);\r
+      gettimemonotonic(nowtv);\r
     end;\r
     if (message=nil) and tv_compare(nowtv,threaddata.nexttimer) then begin\r
       processtimers;\r