Ver Fonte

Allow objpas classes and sysutils units to compile with threading support disabled

git-svn-id: trunk@36107 -
pierre há 8 anos atrás
pai
commit
78343902bf

+ 89 - 18
rtl/objpas/classes/classes.inc

@@ -91,7 +91,12 @@ var
     TThread.SpinWait() }
   SpinWaitDummy: LongWord;
 
+
+{$ifdef FPC_HAS_FEATURE_THREADING}
 threadvar
+{$else}
+var
+{$endif}
   { the instance of the current thread; in case of an external thread this is
     Nil until TThread.GetCurrentThread was called once (the RTLs need to ensure
     that threadvars are initialized with 0!) }
@@ -206,7 +211,9 @@ function ThreadProc(ThreadObjPtr: Pointer): PtrInt;
     Thread.DoTerminate;
     if FreeThread then
       Thread.Free;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     EndThread(Result);
+{$endif}
   end;
 
 { system-dependent code }
@@ -218,7 +225,11 @@ constructor TThread.Create(CreateSuspended: Boolean;
 begin
   inherited Create;
   if FExternalThread then
+{$ifdef FPC_HAS_FEATURE_THREADING}
     FThreadID := GetCurrentThreadID
+{$else}
+    FThreadID := 0{GetCurrentThreadID}
+{$endif}
   else
     SysCreate(CreateSuspended, StackSize);
 end;
@@ -228,8 +239,10 @@ destructor TThread.Destroy;
 begin
   if not FExternalThread then begin
     SysDestroy;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     if FHandle <> TThreadID(0) then
       CloseThread(FHandle);
+{$endif}
   end;
   RemoveQueuedEvents(Self);
   DoneSynchronizeEvent;
@@ -279,10 +292,14 @@ end;
 procedure ThreadQueueAppend(aEntry: TThread.PThreadQueueEntry);
 begin
   { do we really need a synchronized call? }
-  if GetCurrentThreadID = MainThreadID then begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
+  if GetCurrentThreadID = MainThreadID then
+{$endif}
+  begin
     ExecuteThreadQueueEntry(aEntry);
     if not Assigned(aEntry^.SyncEvent) then
       Dispose(aEntry);
+{$ifdef FPC_HAS_FEATURE_THREADING}
   end else begin
     System.EnterCriticalSection(ThreadQueueLock);
     try
@@ -307,6 +324,7 @@ begin
       if Assigned(aEntry^.Exception) then
         raise aEntry^.Exception;
     end;
+{$endif def FPC_HAS_FEATURE_THREADING}
   end;
 end;
 
@@ -320,7 +338,11 @@ procedure TThread.InitSynchronizeEvent;
     FillChar(FSynchronizeEntry^, SizeOf(TThreadQueueEntry), 0);
     FSynchronizeEntry^.Thread := Self;
     FSynchronizeEntry^.ThreadID := ThreadID;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     FSynchronizeEntry^.SyncEvent := RtlEventCreate;
+{$else}
+    FSynchronizeEntry^.SyncEvent := nil{RtlEventCreate};
+{$endif}
   end;
 
 
@@ -329,7 +351,9 @@ procedure TThread.DoneSynchronizeEvent;
     if not Assigned(FSynchronizeEntry) then
       Exit;
 
+{$ifdef FPC_HAS_FEATURE_THREADING}
     RtlEventDestroy(FSynchronizeEntry^.SyncEvent);
+{$endif}
     Dispose(FSynchronizeEntry);
     FSynchronizeEntry := Nil;
   end;
@@ -343,8 +367,13 @@ class procedure TThread.Synchronize(AThread: TThread; AMethod: TThreadMethod);
       { use a local synchronize event }
       New(syncentry);
       FillChar(syncentry^, SizeOf(TThreadQueueEntry), 0);
+{$ifdef FPC_HAS_FEATURE_THREADING}
       syncentry^.ThreadID := GetCurrentThreadID;
       syncentry^.SyncEvent := RtlEventCreate;
+{$else}
+      syncentry^.ThreadID := 0{GetCurrentThreadID};
+      syncentry^.SyncEvent := nil{RtlEventCreate};
+{$endif}
     end else begin
       { the Synchronize event is instantiated on demand }
       AThread.InitSynchronizeEvent;
@@ -361,7 +390,9 @@ class procedure TThread.Synchronize(AThread: TThread; AMethod: TThreadMethod);
 
     if not Assigned(AThread) then begin
       { clean up again }
+{$ifdef FPC_HAS_FEATURE_THREADING}
       RtlEventDestroy(syncentry^.SyncEvent);
+{$endif}
       Dispose(syncentry);
     end;
   end;
@@ -378,16 +409,20 @@ begin
   Result:=ThreadQueueHead;
   if (Result<>Nil) then
     begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
     System.EnterCriticalSection(ThreadQueueLock);
     try
+{$endif}
       Result:=ThreadQueueHead;
       if Result<>Nil then
         ThreadQueueHead:=ThreadQueueHead^.Next;
       if Not Assigned(ThreadQueueHead) then
         ThreadQueueTail := Nil;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     finally
       System.LeaveCriticalSection(ThreadQueueLock);
     end;
+{$endif}
     end;
 end;
 
@@ -403,6 +438,7 @@ begin
   { first sanity check }
   if Not IsMultiThread then
     Exit
+{$ifdef FPC_HAS_FEATURE_THREADING}
   { second sanity check }
   else if GetCurrentThreadID<>MainThreadID then
     raise EThread.CreateFmt(SCheckSynchronizeError,[GetCurrentThreadID]);
@@ -436,7 +472,8 @@ begin
         raise exceptobj;
       end;
     tmpentry := PopThreadQueueHead;
-    end;
+    end
+{$endif};
 end;
 
 
@@ -471,7 +508,11 @@ begin
   New(queueentry);
   FillChar(queueentry^, SizeOf(TThreadQueueEntry), 0);
   queueentry^.Thread := aThread;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   queueentry^.ThreadID := GetCurrentThreadID;
+{$else}
+  queueentry^.ThreadID := 0{GetCurrentThreadID};
+{$endif}
   queueentry^.Method := aMethod;
 
   { the queueentry is freed by CheckSynchronize (or by RemoveQueuedEvents) }
@@ -487,8 +528,10 @@ begin
   if not Assigned(aThread) and not Assigned(aMethod) then
     Exit;
 
+{$ifdef FPC_HAS_FEATURE_THREADING}
   System.EnterCriticalSection(ThreadQueueLock);
   try
+{$endif}
     lastentry := Nil;
     entry := ThreadQueueHead;
     while Assigned(entry) do begin
@@ -525,9 +568,11 @@ begin
       if not Assigned(tmpentry^.SyncEvent) then
         Dispose(tmpentry);
     end;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     System.LeaveCriticalSection(ThreadQueueLock);
   end;
+{$endif}
 end;
 
 
@@ -605,7 +650,9 @@ end;
 
 class procedure TThread.Yield;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   ThreadSwitch;
+{$endif}
 end;
 
 
@@ -656,7 +703,7 @@ begin
   Result := SysUtils.GetTickCount64;
 end;
 
-{ TSimpleThread allows objects to create a threading method without defining 
+{ TSimpleThread allows objects to create a threading method without defining
   a new thread class }
 
 Type
@@ -712,7 +759,7 @@ Type
 
 
 { TSimpleThread }
- 
+
 constructor TSimpleThread.Create(ExecuteMethod: TThreadExecuteHandler; AOnTerminate: TNotifyEvent);
 begin
   FExecuteMethod := ExecuteMethod;
@@ -727,7 +774,7 @@ begin
 end;
 
 { TSimpleStatusThread }
- 
+
 constructor TSimpleStatusThread.Create(ExecuteMethod: TThreadExecuteStatusHandler;AOnStatus : TThreadStatusNotifyEvent; AOnTerminate: TNotifyEvent);
 begin
   FExecuteMethod := ExecuteMethod;
@@ -745,11 +792,11 @@ end;
 
 procedure TSimpleStatusThread.SetStatus(Const AStatus : String);
 begin
-  If (AStatus=FStatus) then 
+  If (AStatus=FStatus) then
     exit;
   FStatus:=AStatus;
-  If Assigned(FOnStatus) then  
-    Synchronize(@DoStatus);  
+  If Assigned(FOnStatus) then
+    Synchronize(@DoStatus);
 end;
 
 procedure TSimpleStatusThread.DoStatus;
@@ -759,7 +806,7 @@ end;
 
 
 { TSimpleProcThread }
- 
+
 constructor TSimpleProcThread.Create(ExecuteMethod: TThreadExecuteCallBack; AData : Pointer; AOnTerminate: TNotifyCallBack);
 begin
   FExecuteMethod := ExecuteMethod;
@@ -780,11 +827,11 @@ procedure TSimpleProcThread.TerminateCallBack(Sender : TObject);
 
 begin
   if Assigned(FCallOnTerminate) then
-    FCallOnTerminate(Sender,FData);  
+    FCallOnTerminate(Sender,FData);
 end;
 
 { TSimpleStatusProcThread }
- 
+
 constructor TSimpleStatusProcThread.Create(ExecuteMethod: TThreadExecuteStatusCallback; AData : Pointer; AOnStatus : TThreadStatusNotifyCallBack; AOnTerminate: TNotifyCallBack);
 begin
   FExecuteMethod := ExecuteMethod;
@@ -805,11 +852,11 @@ end;
 
 procedure TSimpleStatusProcThread.SetStatus(Const AStatus : String);
 begin
-  If (AStatus=FStatus) then 
+  If (AStatus=FStatus) then
     exit;
   FStatus:=AStatus;
-  If Assigned(FOnStatus) then  
-    Synchronize(@DoStatus);  
+  If Assigned(FOnStatus) then
+    Synchronize(@DoStatus);
 end;
 
 procedure TSimpleStatusProcThread.DoStatus;
@@ -821,7 +868,7 @@ procedure TSimpleStatusProcThread.TerminateCallBack(Sender : TObject);
 
 begin
   if Assigned(FCallOnTerminate) then
-    FCallOnTerminate(Sender,FData);  
+    FCallOnTerminate(Sender,FData);
 end;
 
 
@@ -840,7 +887,7 @@ end;
 Class Function TThread.ExecuteInThread(AMethod : TThreadExecuteStatusHandler; AOnStatus : TThreadStatusNotifyEvent; AOnTerminate : TNotifyEvent = Nil) : TThread;
 
 begin
-  If Not Assigned(AOnStatus) then 
+  If Not Assigned(AOnStatus) then
     Raise EThread.Create(SErrStatusCallBackRequired);
   Result:=TSimpleStatusThread.Create(AMethod,AOnStatus,AOnTerminate);
 end;
@@ -848,7 +895,7 @@ end;
 Class Function TThread.ExecuteInThread(AMethod : TThreadExecuteStatusCallback; AOnStatus : TThreadStatusNotifyCallback;AData : Pointer = Nil;  AOnTerminate : TNotifyCallBack = Nil) : TThread;
 
 begin
-  If Not Assigned(AOnStatus) then 
+  If Not Assigned(AOnStatus) then
     Raise EThread.Create(SErrStatusCallBackRequired);
   Result:=TSimpleStatusProcThread.Create(AMethod,AData,AOnStatus,AOnTerminate);
 end;
@@ -1247,12 +1294,16 @@ function DefaultInitHandler(Instance: TComponent; RootAncestor: TClass): Boolean
     end;
 
   begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
     GlobalNameSpace.BeginWrite;
     try
+{$endif}
       result:=doinit(Instance.ClassType);
+{$ifdef FPC_HAS_FEATURE_THREADING}
     finally
       GlobalNameSpace.EndWrite;
     end;
+{$endif}
   end;
 
 
@@ -1390,7 +1441,11 @@ begin
     end;
 end;
 
+{$ifdef FPC_HAS_FEATURE_THREADING}
 threadvar
+{$else}
+var
+{$endif}
   GlobalLoaded, GlobalLists: TFpList;
 
 procedure BeginGlobalLoading;
@@ -2368,12 +2423,20 @@ end;
 
 procedure CommonInit;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   SynchronizeTimeoutEvent:=RtlEventCreate;
   InitCriticalSection(ThreadQueueLock);
   MainThreadID:=GetCurrentThreadID;
+{$else}
+  MainThreadID:=0{GetCurrentThreadID};
+{$endif}
   ExternalThreads := TThreadList.Create;
-  TThread.FProcessorCount := CPUCount;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   InitCriticalsection(ResolveSection);
+  TThread.FProcessorCount := CPUCount;
+{$else}
+  TThread.FProcessorCount := 1{CPUCount};
+{$endif}
   InitHandlerList:=Nil;
   FindGlobalComponentList:=nil;
   IntConstList := TThreadList.Create;
@@ -2389,7 +2452,9 @@ var
   i: Integer;
   tmpentry: TThread.PThreadQueueEntry;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   GlobalNameSpace.BeginWrite;
+{$endif}
   with IntConstList.LockList do
     try
       for i := 0 to Count - 1 do
@@ -2401,7 +2466,9 @@ begin
   ClassList.Free;
   ClassAliasList.Free;
   RemoveFixupReferences(nil, '');
+{$ifdef FPC_HAS_FEATURE_THREADING}
   DoneCriticalsection(ResolveSection);
+{$endif}
   GlobalLists.Free;
   ComponentPages.Free;
   FreeAndNil(NeedResolving);
@@ -2424,7 +2491,9 @@ begin
       ExternalThreads.UnlockList;
     end;
   FreeAndNil(ExternalThreads);
+{$ifdef FPC_HAS_FEATURE_THREADING}
   RtlEventDestroy(SynchronizeTimeoutEvent);
+{$endif}
   { clean up the queue, but keep in mind that the entries used for Synchronize
     are owned by the corresponding TThread }
   while Assigned(ThreadQueueHead) do begin
@@ -2433,7 +2502,9 @@ begin
     if not Assigned(tmpentry^.SyncEvent) then
       Dispose(tmpentry);
   end;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   DoneCriticalSection(ThreadQueueLock);
+{$endif}
 end;
 
 { TFiler implementation }

+ 8 - 6
rtl/objpas/classes/classesh.inc

@@ -390,7 +390,7 @@ type
       { functions and properties to match TBits class }
       procedure SetBit(bit : longint; value : Boolean);
       procedure SetSize(value : longint);
-   Protected   
+   Protected
       procedure CheckBitIndex (Bit : longint;CurrentSize : Boolean);
    public
       { Public declarations }
@@ -669,9 +669,9 @@ type
     function AddObject(const Fmt: string; Args : Array of const; AObject: TObject): Integer; overload;
     procedure Append(const S: string);
     procedure AddStrings(TheStrings: TStrings); overload; virtual;
-    procedure AddStrings(TheStrings: TStrings; ClearFirst : Boolean); overload; 
+    procedure AddStrings(TheStrings: TStrings; ClearFirst : Boolean); overload;
     procedure AddStrings(const TheStrings: array of string); overload; virtual;
-    procedure AddStrings(const TheStrings: array of string; ClearFirst : Boolean); overload; 
+    procedure AddStrings(const TheStrings: array of string; ClearFirst : Boolean); overload;
     Procedure AddText(Const S : String); virtual;
     procedure Assign(Source: TPersistent); override;
     procedure BeginUpdate;
@@ -1579,13 +1579,13 @@ type
 
 { TThread }
   TThread = Class;
-  
+
   EThread = class(Exception);
   EThreadExternalException = class(EThread);
   EThreadDestroyCalled = class(EThread);
   TSynchronizeProcVar = procedure;
   TThreadMethod = procedure of object;
-  
+
   TThreadReportStatus = Procedure(Const status : String) of Object;
 
   TThreadStatusNotifyEvent = Procedure(Sender : TThread; Const status : String) of Object;
@@ -1596,10 +1596,12 @@ type
   TThreadStatusNotifyCallBack = Procedure(Sender : TThread; AData : Pointer; Const status : String);
   TThreadExecuteCallBack = Procedure(AData : Pointer);
   TThreadExecuteStatusCallBack = Procedure(AData : Pointer; ReportStatus : TThreadReportStatus);
-  
+
   TThreadPriority = (tpIdle, tpLowest, tpLower, tpNormal, tpHigher, tpHighest,
     tpTimeCritical);
 
+
+
   TThread = class
   private type
     PThreadQueueEntry = ^TThreadQueueEntry;

+ 14 - 6
rtl/objpas/classes/lists.inc

@@ -154,7 +154,7 @@ begin
   // Shr is used because it is faster than div.
   if (FCapacity > 256) and (FCount < FCapacity shr 2) then
   begin
-    FCapacity := FCapacity shr 1; 
+    FCapacity := FCapacity shr 1;
     ReallocMem(FList, SizeOf(Pointer) * FCapacity);
   end;
 end;
@@ -184,13 +184,13 @@ begin
     For really big lists, (128Mb elements), increase with fixed amount: 16Mb elements (=1/8th of 128Mb).
     For big lists (8mb elements), increase with 1/8th of the size
     For moderate lists (128 or more, increase with 1/4th the size
-    For smaller sizes, increase with 16 or 4  
+    For smaller sizes, increase with 16 or 4
   }
   if FCapacity > 128*1024*1024 then IncSize := 16*1024*1024
   else if FCapacity > 8*1024*1024 then IncSize := FCapacity shr 3
   else if FCapacity > 128 then IncSize := FCapacity shr 2
   else if FCapacity > 8 then IncSize := 16
-  else IncSize := 4; 
+  else IncSize := 4;
   SetCapacity(FCapacity + IncSize);
   Result := Self;
 end;
@@ -232,7 +232,7 @@ begin
     Result:=Count-1;
     while (Result >=0) and (Flist^[Result]<>Item) do
       Result:=Result - 1;
-    end;      
+    end;
 end;
 
 procedure TFPList.Insert(Index: Integer; Item: Pointer);
@@ -410,7 +410,7 @@ procedure TFPList.DoDestUnique(ListA, ListB : TFPList);
       if dest.indexof(src[r]) < 0 then
         self.Add (src[r]);
   end;
-  
+
 var dest : TFPList;
 begin
   if assigned (ListB) then
@@ -845,7 +845,7 @@ procedure TList.DoDestUnique(ListA, ListB : TList);
       if dest.indexof(src[r]) < 0 then
         self.Add (src[r]);
   end;
-  
+
 var dest : TList;
 begin
   if assigned (ListB) then
@@ -965,7 +965,9 @@ constructor TThreadList.Create;
   begin
     inherited Create;
     FDuplicates:=dupIgnore;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     InitCriticalSection(FLock);
+{$endif}
     FList:=TList.Create;
   end;
 
@@ -978,7 +980,9 @@ destructor TThreadList.Destroy;
       inherited Destroy;
     finally
       UnlockList;
+{$ifdef FPC_HAS_FEATURE_THREADING}
       DoneCriticalSection(FLock);
+{$endif}
     end;
   end;
 
@@ -1013,7 +1017,9 @@ procedure TThreadList.Clear;
 function TThreadList.LockList: TList;
   begin
     Result:=FList;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     System.EnterCriticalSection(FLock);
+{$endif}
   end;
 
 
@@ -1030,5 +1036,7 @@ procedure TThreadList.Remove(Item: Pointer);
 
 procedure TThreadList.UnlockList;
   begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
     System.LeaveCriticalSection(FLock);
+{$endif}
   end;

+ 35 - 19
rtl/objpas/classes/resref.inc

@@ -27,12 +27,12 @@ type
     Function RootMatches(ARoot : TComponent) : Boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE} // True if Froot matches or ARoot is nil.
     Function NextRef : TUnresolvedReference; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
   end;
-  
+
   TLocalUnResolvedReference = class(TUnresolvedReference)
     Finstance : TPersistent;
   end;
 
-  // Linked list of TPersistent items that have unresolved properties.  
+  // Linked list of TPersistent items that have unresolved properties.
 
   { TUnResolvedInstance }
 
@@ -51,12 +51,12 @@ type
     Procedure Add(Item : TlinkedListItem); // Add TUnResolvedInstance item to list. Create list if needed
     Destructor Destroy; override; // All elements in list (if any) are removed from the global list.
   end;
-  
+
   // Visitor used to try and resolve instances in the global list
   TResolveReferenceVisitor = Class(TBuildListVisitor)
     Function Visit(Item : TLinkedListItem) : Boolean; override;
   end;
-  
+
   // Visitor used to remove all references to a certain component.
   TRemoveReferenceVisitor = Class(TBuildListVisitor)
     FRef : String;
@@ -73,7 +73,7 @@ type
     Constructor Create(ARoot : TComponent;AList : TStrings);
   end;
 
-  // Visitor used to collect instance names.  
+  // Visitor used to collect instance names.
   TReferenceInstancesVisitor = Class(TLinkedListVisitor)
     FList : TStrings;
     FRef  : String;
@@ -81,7 +81,7 @@ type
     Function Visit(Item : TLinkedListItem) : Boolean; override;
     Constructor Create(ARoot : TComponent;Const ARef : String; AList : TStrings);
   end;
-  
+
   // Visitor used to redirect links to another root component.
   TRedirectReferenceVisitor = Class(TLinkedListVisitor)
     FOld,
@@ -90,7 +90,7 @@ type
     Function Visit(Item : TLinkedListItem) : Boolean; override;
     Constructor Create(ARoot : TComponent;Const AOld,ANew : String);
   end;
-  
+
 var
   NeedResolving : TLinkedList;
   ResolveSection : TRTLCriticalSection;
@@ -100,17 +100,21 @@ Function FindUnresolvedInstance(AInstance: TPersistent) : TUnResolvedInstance;
 
 begin
   Result:=Nil;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(ResolveSection);
   Try
+{$endif}
     If Assigned(NeedResolving) then
       begin
       Result:=TUnResolvedInstance(NeedResolving.Root);
       While (Result<>Nil) and (Result.Instance<>AInstance) do
         Result:=TUnResolvedInstance(Result.Next);
       end;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(ResolveSection);
   end;
+{$endif}
 end;
 
 Function AddtoResolveList(AInstance: TPersistent) : TUnResolvedInstance;
@@ -119,53 +123,65 @@ begin
   Result:=FindUnresolvedInstance(AInstance);
   If (Result=Nil) then
     begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
     EnterCriticalSection(ResolveSection);
     Try
+{$endif}
       If not Assigned(NeedResolving) then
         NeedResolving:=TLinkedList.Create(TUnResolvedInstance);
       Result:=NeedResolving.Add as TUnResolvedInstance;
       Result.Instance:=AInstance;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     finally
       LeaveCriticalSection(ResolveSection);
     end;
+{$endif}
     end;
 end;
 
-// Walk through the global list of instances to be resolved.  
+// Walk through the global list of instances to be resolved.
 
 Procedure VisitResolveList(V : TLinkedListVisitor);
 
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(ResolveSection);
   Try
+{$endif}
     try
       NeedResolving.Foreach(V);
     Finally
       FreeAndNil(V);
-    end;  
+    end;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   Finally
     LeaveCriticalSection(ResolveSection);
-  end;  
+  end;
+{$endif}
 end;
 
 procedure GlobalFixupReferences;
 
 begin
-  If (NeedResolving=Nil) then 
+  If (NeedResolving=Nil) then
     Exit;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   GlobalNameSpace.BeginWrite;
   try
+{$endif}
     VisitResolveList(TResolveReferenceVisitor.Create);
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     GlobalNameSpace.EndWrite;
   end;
+{$endif}
 end;
 
 
 procedure GetFixupReferenceNames(Root: TComponent; Names: TStrings);
 
 begin
-  If (NeedResolving=Nil) then 
+  If (NeedResolving=Nil) then
     Exit;
   VisitResolveList(TReferenceNamesVisitor.Create(Root,Names));
 end;
@@ -236,7 +252,7 @@ begin
     If Result then
       SetObjectProp(Instance, FPropInfo,C);
     end;
-end; 
+end;
 
 Function TUnresolvedReference.RootMatches(ARoot : TComponent) : Boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 
@@ -270,7 +286,7 @@ begin
   Result.FRoot:=ARoot;
 end;
 
-Function TUnResolvedInstance.RootUnresolved : TUnresolvedReference; 
+Function TUnResolvedInstance.RootUnresolved : TUnresolvedReference;
 
 begin
   Result:=Nil;
@@ -314,7 +330,7 @@ begin
   While (R<>Nil) do
     begin
     If R.RootMatches(FRoot) then
-      If (FList.IndexOf(R.FGlobal)=-1) then 
+      If (FList.IndexOf(R.FGlobal)=-1) then
         FList.Add(R.FGlobal);
     R:=R.NextRef;
     end;
@@ -390,7 +406,7 @@ Var
   UI : TUnResolvedInstance;
   R : TUnresolvedReference;
   L : TFPList;
-  
+
 begin
   UI:=TUnResolvedInstance(Item);
   R:=UI.RootUnresolved;
@@ -434,7 +450,7 @@ begin
   If (List=Nil) then
     List:=TFPList.Create;
   List.Add(Item);
-end;  
+end;
 
 Destructor TBuildListVisitor.Destroy;
 
@@ -451,10 +467,10 @@ end;
 
 { TResolveReferenceVisitor }
 
-Function TResolveReferenceVisitor.Visit(Item : TLinkedListItem) : Boolean; 
+Function TResolveReferenceVisitor.Visit(Item : TLinkedListItem) : Boolean;
 
 begin
   If TUnResolvedInstance(Item).ResolveReferences then
     Add(Item);
-  Result:=True;  
+  Result:=True;
 end;

+ 32 - 0
rtl/objpas/sysutils/sysencoding.inc

@@ -17,13 +17,17 @@
 
 class function TEncoding.GetANSI: TEncoding;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(FLock);
   try
+{$endif}
     if not Assigned(FStandardEncodings[seAnsi]) then
       FStandardEncodings[seAnsi] := TMBCSEncoding.Create(DefaultSystemCodePage);
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(FLock);
   end;
+{$endif}
   Result := FStandardEncodings[seAnsi];
 end;
 
@@ -52,25 +56,33 @@ end;
 
 class function TEncoding.GetASCII: TEncoding;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(FLock);
   try
+{$endif}
     if not Assigned(FStandardEncodings[seAscii]) then
       FStandardEncodings[seAscii] := TMBCSEncoding.Create(CP_ASCII);
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(FLock);
   end;
+{$endif}
   Result := FStandardEncodings[seAscii];
 end;
 
 class function TEncoding.GetBigEndianUnicode: TEncoding;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(FLock);
   try
+{$endif}
     if not Assigned(FStandardEncodings[seBigEndianUnicode]) then
       FStandardEncodings[seBigEndianUnicode] := TBigEndianUnicodeEncoding.Create;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(FLock);
   end;
+{$endif}
   Result := FStandardEncodings[seBigEndianUnicode];
 end;
 
@@ -81,37 +93,49 @@ end;
 
 class function TEncoding.GetUnicode: TEncoding;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(FLock);
   try
+{$endif}
     if not Assigned(FStandardEncodings[seUnicode]) then
       FStandardEncodings[seUnicode] := TUnicodeEncoding.Create;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(FLock);
   end;
+{$endif}
   Result := FStandardEncodings[seUnicode];
 end;
 
 class function TEncoding.GetUTF7: TEncoding;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(FLock);
   try
+{$endif}
     if not Assigned(FStandardEncodings[seUTF7]) then
       FStandardEncodings[seUTF7] := TUTF7Encoding.Create;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(FLock);
   end;
+{$endif}
   Result := FStandardEncodings[seUTF7];
 end;
 
 class function TEncoding.GetUTF8: TEncoding;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(FLock);
   try
+{$endif}
     if not Assigned(FStandardEncodings[seUTF8]) then
       FStandardEncodings[seUTF8] := TUTF8Encoding.Create;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(FLock);
   end;
+{$endif}
   Result := FStandardEncodings[seUTF8];
 end;
 
@@ -119,13 +143,17 @@ class procedure TEncoding.FreeEncodings;
 var
   E: TStandardEncoding;
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(FLock);
   try
+{$endif}
     for E := Low(FStandardEncodings) to High(FStandardEncodings) do
       FStandardEncodings[E].Free;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
     LeaveCriticalSection(FLock);
   end;
+{$endif}
 end;
 
 class constructor TEncoding.Create;
@@ -134,13 +162,17 @@ var
 begin
   for E := Low(FStandardEncodings) to High(FStandardEncodings) do
     FStandardEncodings[E] := nil;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   InitCriticalSection(FLock);
+{$endif}
 end;
 
 class destructor TEncoding.Destroy;
 begin
   FreeEncodings;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   DoneCriticalSection(FLock);
+{$endif}
 end;
 
 function TEncoding.Clone: TEncoding;