From d32d0df4855a2ac6e3f5a8ee21d73f4f3030ecac Mon Sep 17 00:00:00 2001 From: marco Date: Sat, 27 Apr 2019 16:14:58 +0000 Subject: [PATCH] --- Merging r41584 into '.': U rtl/amicommon/athreads.pp U rtl/amicommon/tthread.inc --- Recording mergeinfo for merge of r41584 into '.': U . # revisions: 41584 r41584 | karoly | 2019-03-04 02:43:42 +0100 (Mon, 04 Mar 2019) | 1 line Changed paths: M /trunk/rtl/amicommon/athreads.pp M /trunk/rtl/amicommon/tthread.inc amicommon: add some naive RTLEventWaitFor implementation, add long standing tthread.inc patch by Sven. Synchronize/CheckSynchronize should now work on Amiga git-svn-id: branches/fixes_3_2@41940 - --- rtl/amicommon/athreads.pp | 26 ++++++++++++++++++++++++++ rtl/amicommon/tthread.inc | 10 +++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/rtl/amicommon/athreads.pp b/rtl/amicommon/athreads.pp index c170009218..614bdc03b4 100644 --- a/rtl/amicommon/athreads.pp +++ b/rtl/amicommon/athreads.pp @@ -741,6 +741,7 @@ end; Type PINTRTLEvent = ^TINTRTLEvent; TINTRTLEvent = record isset: boolean; + Sem: TSignalSemaphore; // Semaphore to protect the whole stuff end; Function intRTLEventCreate: PRTLEvent; @@ -749,6 +750,8 @@ var p:pintrtlevent; begin new(p); + p^.isset:=false; + InitSemaphore(@p^.Sem); result:=PRTLEVENT(p); end; @@ -766,7 +769,9 @@ var p:pintrtlevent; begin p:=pintrtlevent(aevent); + ObtainSemaphore(@p^.Sem); p^.isset:=true; + ReleaseSemaphore(@p^.Sem); end; @@ -775,7 +780,9 @@ var p:pintrtlevent; begin p:=pintrtlevent(aevent); + ObtainSemaphore(@p^.Sem); p^.isset:=false; + ReleaseSemaphore(@p^.Sem); end; @@ -784,7 +791,15 @@ var p:pintrtlevent; begin p:=pintrtlevent(aevent); + ObtainSemaphore(@p^.Sem); + while not p^.isset do + begin + ReleaseSemaphore(@p^.Sem); + DOSDelay(1); + ObtainSemaphore(@p^.Sem); + end; p^.isset:=false; + ReleaseSemaphore(@p^.Sem); end; procedure intRTLEventWaitForTimeout(AEvent: PRTLEvent;timeout : longint); @@ -792,6 +807,17 @@ var p : pintrtlevent; begin p:=pintrtlevent(aevent); + timeout:=timeout div 20; // DOSDelay expects (1/50 seconds) + ObtainSemaphore(@p^.Sem); + while (not p^.isset) and (timeout > 0) do + begin + ReleaseSemaphore(@p^.Sem); + DOSDelay(1); + dec(timeout); + ObtainSemaphore(@p^.Sem); + end; + p^.isset:=false; + ReleaseSemaphore(@p^.Sem); end; diff --git a/rtl/amicommon/tthread.inc b/rtl/amicommon/tthread.inc index dc62795cf2..302201ae12 100644 --- a/rtl/amicommon/tthread.inc +++ b/rtl/amicommon/tthread.inc @@ -120,6 +120,14 @@ end; function TThread.WaitFor: Integer; begin + if MainThreadID=GetCurrentThreadID then + { + FFinished is set after DoTerminate, which does a synchronize of OnTerminate, + so make sure synchronize works (or indeed any other synchronize that may be + in progress) + } + while not FFinished do + CheckSynchronize(100); + result:=WaitForThreadTerminate(FThreadID,0); - FFinished:=(result = 0); end;