Browse Source

2.0.4: pthread_cond_timedwait needs absolute time (from crossbuilder, issue #7196)

git-svn-id: trunk@4296 -
micha 19 years ago
parent
commit
d0e0ef3d8c
1 changed files with 10 additions and 2 deletions
  1. 10 2
      rtl/unix/cthreads.pp

+ 10 - 2
rtl/unix/cthreads.pp

@@ -554,10 +554,18 @@ procedure intRTLEventWaitForTimeout(AEvent: PRTLEvent;timeout : longint);
     p : pintrtlevent;
     errres : cint;
     timespec : ttimespec;
+    tnow : timeval;
+
   begin
     p:=pintrtlevent(aevent);
-    timespec.tv_sec:=timeout div 1000;
-    timespec.tv_nsec:=(timeout mod 1000)*1000000;
+    fpgettimeofday(@tnow,nil);
+    timespec.tv_sec:=tnow.tv_sec+(timeout div 1000);
+    timespec.tv_nsec:=(timeout mod 1000)*1000000 + tnow.tv_usec*1000;
+    if timespec.tv_nsec >= 1000000000 then
+    begin
+      inc(timespec.tv_sec);
+      dec(timespec.tv_nsec, 1000000000);
+    end;
     errres:=pthread_cond_timedwait(@p^.condvar, @p^.mutex, @timespec);
     if (errres=0) or (errres=ESysETIMEDOUT) then
       pthread_mutex_unlock(@p^.mutex);