|
@@ -16,6 +16,16 @@ type
|
|
var
|
|
var
|
|
ThreadWindow: HWND;
|
|
ThreadWindow: HWND;
|
|
ThreadCount: Integer;
|
|
ThreadCount: Integer;
|
|
|
|
+ { event that happens when gui thread is done executing the method
|
|
|
|
+}
|
|
|
|
+ ExecuteEvent: PRtlEvent;
|
|
|
|
+ { guard for synchronization variables }
|
|
|
|
+ SynchronizeCritSect: systhrds.TRtlCriticalSection;
|
|
|
|
+ { method to execute }
|
|
|
|
+ SynchronizeMethod: TThreadMethod;
|
|
|
|
+ { caught exception in gui thread, to be raised in calling thread }
|
|
|
|
+ SynchronizeException: Exception;
|
|
|
|
+
|
|
|
|
|
|
function ThreadWndProc(Window: HWnd; AMessage:UInt; WParam : WParam; LParam: LParam): Longint; stdcall;
|
|
function ThreadWndProc(Window: HWnd; AMessage:UInt; WParam : WParam; LParam: LParam): Longint; stdcall;
|
|
|
|
|
|
@@ -174,6 +184,7 @@ begin
|
|
SetThreadPriority(FHandle, Priorities[Value]);
|
|
SetThreadPriority(FHandle, Priorities[Value]);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+{ old implementation? :
|
|
procedure TThread.Synchronize(Method: TThreadMethod);
|
|
procedure TThread.Synchronize(Method: TThreadMethod);
|
|
begin
|
|
begin
|
|
FSynchronizeException := nil;
|
|
FSynchronizeException := nil;
|
|
@@ -181,6 +192,42 @@ begin
|
|
SendMessage(ThreadWindow, CM_EXECPROC, 0, Longint(Self));
|
|
SendMessage(ThreadWindow, CM_EXECPROC, 0, Longint(Self));
|
|
if Assigned(FSynchronizeException) then raise FSynchronizeException;
|
|
if Assigned(FSynchronizeException) then raise FSynchronizeException;
|
|
end;
|
|
end;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+procedure TThread.Synchronize(Method: TThreadMethod);
|
|
|
|
+var
|
|
|
|
+ LocalSyncException: Exception;
|
|
|
|
+begin
|
|
|
|
+ if SynchronizeMethodProc = nil then
|
|
|
|
+ { raise some error? }
|
|
|
|
+ exit;
|
|
|
|
+
|
|
|
|
+ systhrds.EnterCriticalSection(SynchronizeCritSect);
|
|
|
|
+ SynchronizeMethod := Method;
|
|
|
|
+ SynchronizeException := nil;
|
|
|
|
+ SynchronizeMethodProc;
|
|
|
|
+ // wait infinitely
|
|
|
|
+ RtlEventWaitFor(ExecuteEvent);
|
|
|
|
+ SynchronizeMethod := nil;
|
|
|
|
+ LocalSyncException := SynchronizeException;
|
|
|
|
+ systhrds.LeaveCriticalSection(SynchronizeCritSect);
|
|
|
|
+ if LocalSyncException <> nil then
|
|
|
|
+ raise LocalSyncException;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure CheckSynchronize;
|
|
|
|
+ { assumes being called from GUI thread }
|
|
|
|
+begin
|
|
|
|
+ if SynchronizeMethod = nil then
|
|
|
|
+ exit;
|
|
|
|
+
|
|
|
|
+ try
|
|
|
|
+ SynchronizeMethod;
|
|
|
|
+ except
|
|
|
|
+ SynchronizeException := Exception(AcquireExceptionObject);
|
|
|
|
+ end;
|
|
|
|
+ RtlEventSetEvent(ExecuteEvent);
|
|
|
|
+end;
|
|
|
|
|
|
procedure TThread.SetSuspended(Value: Boolean);
|
|
procedure TThread.SetSuspended(Value: Boolean);
|
|
begin
|
|
begin
|
|
@@ -219,7 +266,10 @@ begin
|
|
end;
|
|
end;
|
|
{
|
|
{
|
|
$Log$
|
|
$Log$
|
|
- Revision 1.2 2004-01-29 16:58:28 marco
|
|
|
|
|
|
+ Revision 1.3 2004-12-23 09:42:42 marco
|
|
|
|
+ * first tthread.synchronize support (merged neli's patches)
|
|
|
|
+
|
|
|
|
+ Revision 1.2 2004/01/29 16:58:28 marco
|
|
* threadproc is passed to OS and must be stdcall;
|
|
* threadproc is passed to OS and must be stdcall;
|
|
|
|
|
|
Revision 1.1 2003/10/06 21:01:07 peter
|
|
Revision 1.1 2003/10/06 21:01:07 peter
|