Implemeted threadsafecall in a cross-component way. Starting on the interface for CPascal now...

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@469 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
BenLand100 2010-01-25 21:37:33 +00:00
parent b1d07ff6d4
commit 331255a0be
4 changed files with 118 additions and 118 deletions

View File

@ -10,7 +10,7 @@
<TargetFileExt Value=""/>
<Title Value="Simba"/>
<UseXPManifest Value="True"/>
<ActiveEditorIndexAtStart Value="8"/>
<ActiveEditorIndexAtStart Value="10"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
@ -139,9 +139,10 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="TestUnit"/>
<CursorPos X="37" Y="1704"/>
<TopLine Value="1687"/>
<EditorIndex Value="8"/>
<ComponentState Value="1"/>
<CursorPos X="10" Y="1718"/>
<TopLine Value="1702"/>
<EditorIndex Value="9"/>
<UsageCount Value="202"/>
<Loaded Value="True"/>
</Unit13>
@ -266,8 +267,8 @@
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="mmlpsthread"/>
<CursorPos X="26" Y="250"/>
<TopLine Value="225"/>
<CursorPos X="47" Y="337"/>
<TopLine Value="321"/>
<EditorIndex Value="6"/>
<UsageCount Value="202"/>
<Loaded Value="True"/>
@ -350,7 +351,7 @@
<UnitName Value="bitmaps"/>
<CursorPos X="12" Y="93"/>
<TopLine Value="83"/>
<EditorIndex Value="10"/>
<EditorIndex Value="11"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
</Unit42>
@ -496,9 +497,9 @@
<Unit64>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/other.inc"/>
<CursorPos X="23" Y="107"/>
<TopLine Value="95"/>
<EditorIndex Value="9"/>
<UsageCount Value="44"/>
<TopLine Value="7"/>
<EditorIndex Value="10"/>
<UsageCount Value="45"/>
<Loaded Value="True"/>
</Unit64>
<Unit65>
@ -625,8 +626,10 @@
<IsPartOfProject Value="True"/>
<UnitName Value="windowselector"/>
<CursorPos X="37" Y="34"/>
<TopLine Value="12"/>
<TopLine Value="176"/>
<EditorIndex Value="8"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit82>
<Unit83>
<Filename Value="../../../usr/lib64/fpc/2.2.4/source/rtl/objpas/classes/classesh.inc"/>
@ -768,7 +771,7 @@
<CursorPos X="12" Y="63"/>
<TopLine Value="29"/>
<EditorIndex Value="1"/>
<UsageCount Value="19"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit103>
<Unit104>
@ -889,7 +892,7 @@
<ResourceBaseClass Value="Frame"/>
<UnitName Value="framescript"/>
<CursorPos X="23" Y="72"/>
<TopLine Value="55"/>
<TopLine Value="223"/>
<EditorIndex Value="7"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
@ -1591,7 +1594,7 @@
<UnitName Value="framefunctionlist"/>
<CursorPos X="26" Y="295"/>
<TopLine Value="7"/>
<UsageCount Value="186"/>
<UsageCount Value="188"/>
</Unit223>
<Unit224>
<Filename Value="../../../usr/local/share/lazarus/lcl/comctrls.pp"/>
@ -1646,7 +1649,7 @@
<UnitName Value="simpleanalyzer"/>
<CursorPos X="52" Y="104"/>
<TopLine Value="193"/>
<UsageCount Value="173"/>
<UsageCount Value="175"/>
</Unit231>
<Unit232>
<Filename Value="../../Units/Misc/mPasLex.pas"/>
@ -1704,10 +1707,10 @@
</Unit239>
<Unit240>
<Filename Value="../../Units/MMLAddon/PSInc/psexportedmethods.inc"/>
<CursorPos X="3" Y="100"/>
<TopLine Value="72"/>
<CursorPos X="89" Y="99"/>
<TopLine Value="78"/>
<EditorIndex Value="2"/>
<UsageCount Value="30"/>
<UsageCount Value="31"/>
<Loaded Value="True"/>
</Unit240>
<Unit241>
@ -1723,7 +1726,7 @@
<UnitName Value="updater"/>
<CursorPos X="38" Y="211"/>
<TopLine Value="65"/>
<UsageCount Value="146"/>
<UsageCount Value="148"/>
</Unit242>
<Unit243>
<Filename Value="updateform.pas"/>
@ -1734,7 +1737,7 @@
<ComponentState Value="1"/>
<CursorPos X="111" Y="102"/>
<TopLine Value="207"/>
<UsageCount Value="141"/>
<UsageCount Value="143"/>
</Unit243>
<Unit244>
<Filename Value="../../../Documents/lazarus/lcl/fileutil.pas"/>
@ -1855,7 +1858,7 @@
<UnitName Value="simbasettings"/>
<CursorPos X="26" Y="9"/>
<TopLine Value="11"/>
<UsageCount Value="104"/>
<UsageCount Value="106"/>
</Unit261>
<Unit262>
<Filename Value="../../Units/MMLAddon/settings.pas"/>
@ -1893,7 +1896,7 @@
<UnitName Value="reportbug"/>
<CursorPos X="53" Y="23"/>
<TopLine Value="21"/>
<UsageCount Value="87"/>
<UsageCount Value="89"/>
</Unit266>
<Unit267>
<Filename Value="../../Units/Synapse/synsock.pas"/>
@ -1950,7 +1953,7 @@
<UnitName Value="newinternets"/>
<CursorPos X="37" Y="171"/>
<TopLine Value="153"/>
<UsageCount Value="83"/>
<UsageCount Value="85"/>
</Unit274>
<Unit275>
<Filename Value="reportbug.lrs"/>
@ -1996,19 +1999,19 @@
<Unit281>
<Filename Value="../../Units/MMLCore/iomanager.pas"/>
<UnitName Value="IOManager"/>
<CursorPos X="67" Y="53"/>
<TopLine Value="34"/>
<CursorPos X="15" Y="600"/>
<TopLine Value="379"/>
<EditorIndex Value="0"/>
<UsageCount Value="33"/>
<UsageCount Value="34"/>
<Loaded Value="True"/>
</Unit281>
<Unit282>
<Filename Value="../../Units/MMLCore/os_linux.pas"/>
<UnitName Value="os_linux"/>
<CursorPos X="36" Y="69"/>
<TopLine Value="56"/>
<TopLine Value="34"/>
<EditorIndex Value="5"/>
<UsageCount Value="32"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit282>
<Unit283>
@ -2021,10 +2024,10 @@
<Unit284>
<Filename Value="../../Units/MMLCore/os_windows.pas"/>
<UnitName Value="os_windows"/>
<CursorPos X="22" Y="164"/>
<TopLine Value="155"/>
<EditorIndex Value="11"/>
<UsageCount Value="28"/>
<CursorPos X="9" Y="75"/>
<TopLine Value="67"/>
<EditorIndex Value="12"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit284>
<Unit285>
@ -2047,7 +2050,7 @@
<UnitName Value="libloader"/>
<CursorPos X="1" Y="149"/>
<TopLine Value="128"/>
<UsageCount Value="41"/>
<UsageCount Value="43"/>
</Unit287>
<Unit288>
<Filename Value="../../Units/MMLAddon/tpa.pas"/>
@ -2061,7 +2064,7 @@
<CursorPos X="8" Y="157"/>
<TopLine Value="140"/>
<EditorIndex Value="4"/>
<UsageCount Value="18"/>
<UsageCount Value="19"/>
<Loaded Value="True"/>
</Unit289>
<Unit290>
@ -2088,123 +2091,123 @@
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="223" Column="14" TopLine="206"/>
<Caret Line="118" Column="15" TopLine="101"/>
</Position1>
<Position2>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="239" Column="11" TopLine="229"/>
<Caret Line="129" Column="63" TopLine="101"/>
</Position2>
<Position3>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="377" Column="34" TopLine="349"/>
<Caret Line="369" Column="14" TopLine="352"/>
</Position3>
<Position4>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="118" Column="15" TopLine="101"/>
<Caret Line="99" Column="70" TopLine="67"/>
</Position4>
<Position5>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="129" Column="63" TopLine="101"/>
<Caret Line="261" Column="8" TopLine="246"/>
</Position5>
<Position6>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="369" Column="14" TopLine="352"/>
<Caret Line="308" Column="4" TopLine="292"/>
</Position6>
<Position7>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="99" Column="70" TopLine="67"/>
<Caret Line="310" Column="16" TopLine="297"/>
</Position7>
<Position8>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="261" Column="8" TopLine="246"/>
<Filename Value="../../Units/MMLAddon/PSInc/psexportedmethods.inc"/>
<Caret Line="59" Column="40" TopLine="36"/>
</Position8>
<Position9>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="308" Column="4" TopLine="292"/>
<Caret Line="127" Column="19" TopLine="101"/>
</Position9>
<Position10>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="310" Column="16" TopLine="297"/>
<Caret Line="59" Column="22" TopLine="42"/>
</Position10>
<Position11>
<Filename Value="../../Units/MMLAddon/PSInc/psexportedmethods.inc"/>
<Caret Line="59" Column="40" TopLine="36"/>
<Caret Line="24" Column="28" TopLine="7"/>
</Position11>
<Position12>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="127" Column="19" TopLine="101"/>
</Position12>
<Position13>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="59" Column="22" TopLine="42"/>
</Position13>
<Position14>
<Filename Value="../../Units/MMLAddon/PSInc/psexportedmethods.inc"/>
<Caret Line="24" Column="28" TopLine="7"/>
</Position14>
<Position15>
<Filename Value="../../Units/MMLAddon/PSInc/psexportedmethods.inc"/>
<Caret Line="30" Column="24" TopLine="13"/>
</Position15>
<Position16>
</Position12>
<Position13>
<Filename Value="../../Units/MMLAddon/PSInc/psexportedmethods.inc"/>
<Caret Line="24" Column="3" TopLine="7"/>
</Position16>
<Position17>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="134" Column="37" TopLine="243"/>
</Position17>
<Position18>
</Position13>
<Position14>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="387" Column="6" TopLine="374"/>
</Position18>
<Position19>
</Position14>
<Position15>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="644" Column="12" TopLine="622"/>
</Position19>
<Position20>
</Position15>
<Position16>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="133" Column="36" TopLine="113"/>
</Position20>
<Position21>
</Position16>
<Position17>
<Filename Value="framescript.pas"/>
<Caret Line="101" Column="1" TopLine="98"/>
</Position21>
<Position22>
</Position17>
<Position18>
<Filename Value="framescript.pas"/>
<Caret Line="73" Column="41" TopLine="54"/>
</Position22>
<Position23>
</Position18>
<Position19>
<Filename Value="testunit.pas"/>
<Caret Line="1550" Column="3" TopLine="1548"/>
</Position19>
<Position20>
<Filename Value="testunit.pas"/>
<Caret Line="541" Column="21" TopLine="518"/>
</Position20>
<Position21>
<Filename Value="testunit.pas"/>
<Caret Line="536" Column="30" TopLine="519"/>
</Position21>
<Position22>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="97" Column="54" TopLine="73"/>
</Position22>
<Position23>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="240" Column="69" TopLine="223"/>
</Position23>
<Position24>
<Filename Value="testunit.pas"/>
<Caret Line="541" Column="21" TopLine="518"/>
<Caret Line="550" Column="46" TopLine="532"/>
</Position24>
<Position25>
<Filename Value="testunit.pas"/>
<Caret Line="536" Column="30" TopLine="519"/>
<Caret Line="636" Column="33" TopLine="613"/>
</Position25>
<Position26>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="97" Column="54" TopLine="73"/>
<Filename Value="testunit.pas"/>
<Caret Line="1439" Column="24" TopLine="1422"/>
</Position26>
<Position27>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="240" Column="69" TopLine="223"/>
<Caret Line="46" Column="30" TopLine="32"/>
</Position27>
<Position28>
<Filename Value="testunit.pas"/>
<Caret Line="550" Column="46" TopLine="532"/>
<Caret Line="1704" Column="37" TopLine="1791"/>
</Position28>
<Position29>
<Filename Value="testunit.pas"/>
<Caret Line="636" Column="33" TopLine="613"/>
<Caret Line="1718" Column="79" TopLine="1699"/>
</Position29>
<Position30>
<Filename Value="testunit.pas"/>
<Caret Line="1439" Column="24" TopLine="1422"/>
<Caret Line="1711" Column="38" TopLine="1696"/>
</Position30>
</JumpHistory>
</ProjectOptions>

View File

@ -1699,20 +1699,32 @@ end;
procedure TForm1.SafeCallThread;
var
thread: TMThread;
begin
Writeln('Executing : ' + CurrentSyncInfo.MethodName);
mmlpsthread.CurrThread := TMThread(CurrentSyncInfo.OldThread);
with CurrentSyncInfo.PSScript do
begin;
OnLine:=@OnLinePSScript;
CurrentSyncInfo.Res:= Exec.RunProcPVar(CurrentSyncInfo.V,Exec.GetProc(CurrentSyncInfo.MethodName));
Online := nil;
thread:= TMThread(CurrentSyncInfo.OldThread);
mmlpsthread.CurrThread:= thread;
try
if thread is TPSThread then
begin
with TPSThread(thread).PSScript do
begin
OnLine:=@OnLinePSScript;
CurrentSyncInfo.Res:= Exec.RunProcPVar(CurrentSyncInfo.V,Exec.GetProc(CurrentSyncInfo.MethodName));
Online := nil;
end;
end else
begin
raise Exception.Create('ThreadSafeCall not implemented on this client');
end;
finally
mmlpsthread.CurrThread:= nil;
end;
mmlpsthread.CurrThread := nil;
end;
function TForm1.OpenScript: boolean;
begin;
begin
Result := False;
if CanExitOrOpen = false then
Exit;

View File

@ -21,7 +21,7 @@
psexportedmethods.inc for the Mufasa Macro Library
}
//AddFunction(@ThreadSafeCall,'function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;');
AddFunction(@ThreadSafeCall,'function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;');
AddFunction(nil,'procedure Writeln(x);'); //We use special function for this
{ DTM }
@ -97,7 +97,6 @@ AddFunction(@DisplayDebugImgWindow,'procedure DisplayDebugImgWindow(w, h: intege
AddFunction(@DrawBitmapDebugImg,'procedure DrawBitmapDebugImg(bmp: integer);');
AddFunction(@GetDebugBitmap,'function GetDebugBitmap: integer;');
AddFunction(@Random,'function Random(Int: integer): integer;');
//AddFunction(@NewThreadCall,'function NewThreadCall(procname : string) : cardinal');
AddFunction(@ClearDebug,'procedure ClearDebug;');

View File

@ -44,7 +44,6 @@ type
Res : Variant;
SyncMethod : procedure of object;
OldThread : TThread;
PSScript : TPSScript;
end;
TWritelnProc = procedure(s: string);
@ -247,7 +246,7 @@ begin
ErrorData^.ErrType:= ErrorType;
ErrorData^.Module:= ErrorModule;
ErrorData^.IncludePath:= IncludePath;
CurrThread.Synchronize(OnError); //what does this do???
CurrThread.Synchronize(OnError);
end;
procedure TMThread.OnThreadTerminate(Sender: TObject);
@ -332,6 +331,15 @@ begin
FontPath:= FontP;
end;
function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;
begin
CurrThread.SyncInfo^.MethodName:= ProcName;
CurrThread.SyncInfo^.V:= V;
CurrThread.SyncInfo^.OldThread := CurrThread;
CurrThread.Synchronize(CurrThread.SyncInfo^.SyncMethod);
Result := CurrThread.SyncInfo^.Res;
end;
{$I PSInc/Wrappers/other.inc}
{$I PSInc/Wrappers/bitmap.inc}
{$I PSInc/Wrappers/window.inc}
@ -397,28 +405,6 @@ end;
well, it will really make the unit more straightforward to use and read.
}
{function NewThreadCall(Procname : string) : Cardinal;
begin;
result := CurrThread.PSScript.Exec.GetVar(Procname);
end;}
{function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;
begin;
CurrThread.SyncInfo^.MethodName:= ProcName;
CurrThread.SyncInfo^.V:= V;
CurrThread.SyncInfo^.PSScript := CurrThread.PSScript;
CurrThread.SyncInfo^.OldThread := CurrThread;
CurrThread.Synchronize(CurrThread.SyncInfo^.SyncMethod);
Result := CurrThread.SyncInfo^.Res;
// Writeln('We have a length of: ' + inttostr(length(v)));
// Try
// Result := CurrThread.PSScript.Exec.RunProcPVar(v,CurrThread.PSScript.Exec.GetProc(Procname));
// Except
// Writeln('We has some errors :-(');
// end;
end;}
constructor TPSThread.Create(CreateSuspended : boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
begin
SyncInfo:= TheSyncInfo;