Browse Source

Guard critical section procedure calls with ifdef FPC_HAS_FEATURE_THREADING

git-svn-id: trunk@36111 -
pierre 8 years ago
parent
commit
9ca8bd41ca

+ 8 - 0
packages/rtl-generics/src/generics.collections.pas

@@ -996,7 +996,9 @@ constructor TThreadList<T>.Create;
 begin
   inherited Create;
   FDuplicates:=dupIgnore;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   InitCriticalSection(FLock);
+{$endif}
   FList := TList<T>.Create;
 end;
 
@@ -1008,7 +1010,9 @@ begin
     inherited Destroy;
   finally
     UnlockList;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     DoneCriticalSection(FLock);
+{$endif}
   end;
 end;
 
@@ -1048,12 +1052,16 @@ end;
 function TThreadList<T>.LockList: TList<T>;
 begin
   Result:=FList;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   System.EnterCriticalSection(FLock);
+{$endif}
 end;
 
 procedure TThreadList<T>.UnlockList;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   System.LeaveCriticalSection(FLock);
+{$endif}
 end;
 
 { TQueue<T>.TEnumerator }

+ 12 - 0
packages/rtl-objpas/src/inc/rtti.pp

@@ -315,9 +315,13 @@ function TRttiPool.GetTypes: specialize TArray<TRttiType>;
 begin
   if not Assigned(FTypesList) then
     Exit(Nil);
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalsection(FLock);
+{$endif}
   Result := Copy(FTypesList, 0, FTypeCount);
+{$ifdef FPC_HAS_FEATURE_THREADING}
   LeaveCriticalsection(FLock);
+{$endif}
 end;
 
 function TRttiPool.GetType(ATypeInfo: PTypeInfo): TRttiType;
@@ -326,7 +330,9 @@ var
 begin
   if not Assigned(ATypeInfo) then
     Exit(Nil);
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalsection(FLock);
+{$endif}
   Result := Nil;
   for i := 0 to FTypeCount - 1 do
     begin
@@ -356,12 +362,16 @@ begin
       FTypesList[FTypeCount] := Result;
       Inc(FTypeCount);
     end;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   LeaveCriticalsection(FLock);
+{$endif}
 end;
 
 constructor TRttiPool.Create;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   InitCriticalSection(FLock);
+{$endif}
   SetLength(FTypesList, 32);
 end;
 
@@ -371,7 +381,9 @@ var
 begin
   for i := 0 to length(FTypesList)-1 do
     FTypesList[i].Free;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   DoneCriticalsection(FLock);
+{$endif}
   inherited Destroy;
 end;
 

+ 24 - 0
packages/rtl-objpas/src/inc/variants.pp

@@ -3584,8 +3584,10 @@ function FindCustomVariantType(const aVarType: TVarType; out CustomVariantType:
     Result:=(aVarType>=CMinVarType);
     if Result then
       begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
         EnterCriticalSection(customvarianttypelock);
         try
+{$endif}
           Result:=(aVarType-CMinVarType)<=high(customvarianttypes);
           if Result then
             begin
@@ -3593,9 +3595,11 @@ function FindCustomVariantType(const aVarType: TVarType; out CustomVariantType:
               Result:=assigned(CustomVariantType) and
                (CustomVariantType<>InvalidCustomVariantType);
             end;
+{$ifdef FPC_HAS_FEATURE_THREADING}
         finally
           LeaveCriticalSection(customvarianttypelock);
         end;
+{$endif}
       end;
   end;
 
@@ -3608,8 +3612,10 @@ function FindCustomVariantType(const TypeName: string;  out CustomVariantType: T
   begin
     ShortTypeName:=TypeName;  // avoid conversion in the loop
     result:=False;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     EnterCriticalSection(customvarianttypelock);
     try
+{$endif}
       for i:=low(customvarianttypes) to high(customvarianttypes) do
         begin
           tmp:=customvarianttypes[i];
@@ -3621,9 +3627,11 @@ function FindCustomVariantType(const TypeName: string;  out CustomVariantType: T
               Exit;
             end;
         end;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     finally
       LeaveCriticalSection(customvarianttypelock);
     end;
+{$endif}
   end;
 
 function Unassigned: Variant; // Unassigned standard constant
@@ -3869,8 +3877,10 @@ procedure RegisterCustomVariantType(obj: TCustomVariantType; RequestedVarType: T
 var
   index,L: Integer;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(customvarianttypelock);
   try
+{$endif}
     L:=Length(customvarianttypes);
     if UseFirstAvailable then
     begin
@@ -3898,9 +3908,11 @@ begin
     end;
     customvarianttypes[index]:=obj;
     obj.FVarType:=RequestedVarType;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(customvarianttypelock);
   end;
+{$endif}
 end;
 
 constructor TCustomVariantType.Create;
@@ -3916,13 +3928,17 @@ end;
 
 destructor TCustomVariantType.Destroy;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(customvarianttypelock);
   try
+{$endif}
     if FVarType<>0 then
       customvarianttypes[FVarType-CMinVarType]:=InvalidCustomVariantType;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(customvarianttypelock);
   end;
+{$endif}
   inherited Destroy;
 end;
 
@@ -4648,7 +4664,9 @@ var
   i : LongInt;
 
 Initialization
+{$ifdef FPC_HAS_FEATURE_THREADING}
   InitCriticalSection(customvarianttypelock);
+{$endif}
   // start with one-less value, so first increment yields CFirstUserType
   customvariantcurrtype:=CFirstUserType-1;
   SetSysVariantManager;
@@ -4664,14 +4682,20 @@ Initialization
   InvalidCustomVariantType:=TCustomVariantType(-1);
   SetLength(customvarianttypes,CFirstUserType);
 Finalization
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(customvarianttypelock);
   try
+{$endif}
     for i:=0 to high(customvarianttypes) do
       if customvarianttypes[i]<>InvalidCustomVariantType then
         customvarianttypes[i].Free;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(customvarianttypelock);
   end;
+{$endif}
   UnSetSysVariantManager;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   DoneCriticalSection(customvarianttypelock);
+{$endif}
 end.