summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2019-06-19 06:25:02 +0000
committermichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2019-06-19 06:25:02 +0000
commit2842651620a3d76a00e490ada563c60a165aa86d (patch)
tree45ef3d8a1fa9744a698180b3a4eb2fa817387b03
parent776e508e7dc00a256371a0412319df33367f630c (diff)
downloadfpc-2842651620a3d76a00e490ada563c60a165aa86d.tar.gz
* Patch from Pascal Riekenberg to make component loading thread safe (bug ID 35638)
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@42248 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--rtl/objpas/classes/classesh.inc3
-rw-r--r--rtl/objpas/classes/reader.inc27
2 files changed, 25 insertions, 5 deletions
diff --git a/rtl/objpas/classes/classesh.inc b/rtl/objpas/classes/classesh.inc
index cd9fb528df..871e605e20 100644
--- a/rtl/objpas/classes/classesh.inc
+++ b/rtl/objpas/classes/classesh.inc
@@ -1442,6 +1442,7 @@ type
FParent: TComponent;
FFixups: TObject;
FLoaded: TFpList;
+ FLock: TRTLCriticalSection;
FOnFindMethod: TFindMethodEvent;
FOnSetMethodProperty: TSetMethodPropertyEvent;
FOnSetName: TSetNameEvent;
@@ -1456,6 +1457,8 @@ type
FOnReadStringProperty:TReadWriteStringPropertyEvent;
procedure DoFixupReferences;
function FindComponentClass(const AClassName: string): TComponentClass;
+ procedure Lock;
+ procedure Unlock;
protected
function Error(const Message: string): Boolean; virtual;
function FindMethod(ARoot: TComponent; const AMethodName: string): CodePointer; virtual;
diff --git a/rtl/objpas/classes/reader.inc b/rtl/objpas/classes/reader.inc
index cc99a8f299..3f19bdf49f 100644
--- a/rtl/objpas/classes/reader.inc
+++ b/rtl/objpas/classes/reader.inc
@@ -609,14 +609,26 @@ begin
If (Stream=Nil) then
Raise EReadError.Create(SEmptyStreamIllegalReader);
FDriver := CreateDriver(Stream, BufSize);
+ InitCriticalSection(FLock);
end;
destructor TReader.Destroy;
begin
+ DoneCriticalSection(FLock);
FDriver.Free;
inherited Destroy;
end;
+procedure TReader.Lock;
+begin
+ EnterCriticalSection(FLock);
+end;
+
+procedure TReader.Unlock;
+begin
+ LeaveCriticalSection(FLock);
+end;
+
procedure TReader.FlushBuffer;
begin
Driver.FlushBuffer;
@@ -1476,12 +1488,17 @@ begin
{ Don't use Result.Name directly, as this would influence
FindGlobalComponent in successive loop runs }
ResultName := CompName;
- while Assigned(FindGlobalComponent(ResultName)) do
- begin
- Inc(i);
- ResultName := CompName + '_' + IntToStr(i);
+ Lock;
+ try
+ while Assigned(FindGlobalComponent(ResultName)) do
+ begin
+ Inc(i);
+ ResultName := CompName + '_' + IntToStr(i);
+ end;
+ Result.Name := ResultName;
+ finally
+ Unlock;
end;
- Result.Name := ResultName;
end;
end;