Browse Source

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

git-svn-id: trunk@36107 -
pierre 8 years ago
parent
commit
78343902bf

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

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

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

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

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

@@ -154,7 +154,7 @@ begin
   // Shr is used because it is faster than div.
   // Shr is used because it is faster than div.
   if (FCapacity > 256) and (FCount < FCapacity shr 2) then
   if (FCapacity > 256) and (FCount < FCapacity shr 2) then
   begin
   begin
-    FCapacity := FCapacity shr 1; 
+    FCapacity := FCapacity shr 1;
     ReallocMem(FList, SizeOf(Pointer) * FCapacity);
     ReallocMem(FList, SizeOf(Pointer) * FCapacity);
   end;
   end;
 end;
 end;
@@ -184,13 +184,13 @@ begin
     For really big lists, (128Mb elements), increase with fixed amount: 16Mb elements (=1/8th of 128Mb).
     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 big lists (8mb elements), increase with 1/8th of the size
     For moderate lists (128 or more, increase with 1/4th 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
   if FCapacity > 128*1024*1024 then IncSize := 16*1024*1024
   else if FCapacity > 8*1024*1024 then IncSize := FCapacity shr 3
   else if FCapacity > 8*1024*1024 then IncSize := FCapacity shr 3
   else if FCapacity > 128 then IncSize := FCapacity shr 2
   else if FCapacity > 128 then IncSize := FCapacity shr 2
   else if FCapacity > 8 then IncSize := 16
   else if FCapacity > 8 then IncSize := 16
-  else IncSize := 4; 
+  else IncSize := 4;
   SetCapacity(FCapacity + IncSize);
   SetCapacity(FCapacity + IncSize);
   Result := Self;
   Result := Self;
 end;
 end;
@@ -232,7 +232,7 @@ begin
     Result:=Count-1;
     Result:=Count-1;
     while (Result >=0) and (Flist^[Result]<>Item) do
     while (Result >=0) and (Flist^[Result]<>Item) do
       Result:=Result - 1;
       Result:=Result - 1;
-    end;      
+    end;
 end;
 end;
 
 
 procedure TFPList.Insert(Index: Integer; Item: Pointer);
 procedure TFPList.Insert(Index: Integer; Item: Pointer);
@@ -410,7 +410,7 @@ procedure TFPList.DoDestUnique(ListA, ListB : TFPList);
       if dest.indexof(src[r]) < 0 then
       if dest.indexof(src[r]) < 0 then
         self.Add (src[r]);
         self.Add (src[r]);
   end;
   end;
-  
+
 var dest : TFPList;
 var dest : TFPList;
 begin
 begin
   if assigned (ListB) then
   if assigned (ListB) then
@@ -845,7 +845,7 @@ procedure TList.DoDestUnique(ListA, ListB : TList);
       if dest.indexof(src[r]) < 0 then
       if dest.indexof(src[r]) < 0 then
         self.Add (src[r]);
         self.Add (src[r]);
   end;
   end;
-  
+
 var dest : TList;
 var dest : TList;
 begin
 begin
   if assigned (ListB) then
   if assigned (ListB) then
@@ -965,7 +965,9 @@ constructor TThreadList.Create;
   begin
   begin
     inherited Create;
     inherited Create;
     FDuplicates:=dupIgnore;
     FDuplicates:=dupIgnore;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     InitCriticalSection(FLock);
     InitCriticalSection(FLock);
+{$endif}
     FList:=TList.Create;
     FList:=TList.Create;
   end;
   end;
 
 
@@ -978,7 +980,9 @@ destructor TThreadList.Destroy;
       inherited Destroy;
       inherited Destroy;
     finally
     finally
       UnlockList;
       UnlockList;
+{$ifdef FPC_HAS_FEATURE_THREADING}
       DoneCriticalSection(FLock);
       DoneCriticalSection(FLock);
+{$endif}
     end;
     end;
   end;
   end;
 
 
@@ -1013,7 +1017,9 @@ procedure TThreadList.Clear;
 function TThreadList.LockList: TList;
 function TThreadList.LockList: TList;
   begin
   begin
     Result:=FList;
     Result:=FList;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     System.EnterCriticalSection(FLock);
     System.EnterCriticalSection(FLock);
+{$endif}
   end;
   end;
 
 
 
 
@@ -1030,5 +1036,7 @@ procedure TThreadList.Remove(Item: Pointer);
 
 
 procedure TThreadList.UnlockList;
 procedure TThreadList.UnlockList;
   begin
   begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
     System.LeaveCriticalSection(FLock);
     System.LeaveCriticalSection(FLock);
+{$endif}
   end;
   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 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}
     Function NextRef : TUnresolvedReference; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
   end;
   end;
-  
+
   TLocalUnResolvedReference = class(TUnresolvedReference)
   TLocalUnResolvedReference = class(TUnresolvedReference)
     Finstance : TPersistent;
     Finstance : TPersistent;
   end;
   end;
 
 
-  // Linked list of TPersistent items that have unresolved properties.  
+  // Linked list of TPersistent items that have unresolved properties.
 
 
   { TUnResolvedInstance }
   { TUnResolvedInstance }
 
 
@@ -51,12 +51,12 @@ type
     Procedure Add(Item : TlinkedListItem); // Add TUnResolvedInstance item to list. Create list if needed
     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.
     Destructor Destroy; override; // All elements in list (if any) are removed from the global list.
   end;
   end;
-  
+
   // Visitor used to try and resolve instances in the global list
   // Visitor used to try and resolve instances in the global list
   TResolveReferenceVisitor = Class(TBuildListVisitor)
   TResolveReferenceVisitor = Class(TBuildListVisitor)
     Function Visit(Item : TLinkedListItem) : Boolean; override;
     Function Visit(Item : TLinkedListItem) : Boolean; override;
   end;
   end;
-  
+
   // Visitor used to remove all references to a certain component.
   // Visitor used to remove all references to a certain component.
   TRemoveReferenceVisitor = Class(TBuildListVisitor)
   TRemoveReferenceVisitor = Class(TBuildListVisitor)
     FRef : String;
     FRef : String;
@@ -73,7 +73,7 @@ type
     Constructor Create(ARoot : TComponent;AList : TStrings);
     Constructor Create(ARoot : TComponent;AList : TStrings);
   end;
   end;
 
 
-  // Visitor used to collect instance names.  
+  // Visitor used to collect instance names.
   TReferenceInstancesVisitor = Class(TLinkedListVisitor)
   TReferenceInstancesVisitor = Class(TLinkedListVisitor)
     FList : TStrings;
     FList : TStrings;
     FRef  : String;
     FRef  : String;
@@ -81,7 +81,7 @@ type
     Function Visit(Item : TLinkedListItem) : Boolean; override;
     Function Visit(Item : TLinkedListItem) : Boolean; override;
     Constructor Create(ARoot : TComponent;Const ARef : String; AList : TStrings);
     Constructor Create(ARoot : TComponent;Const ARef : String; AList : TStrings);
   end;
   end;
-  
+
   // Visitor used to redirect links to another root component.
   // Visitor used to redirect links to another root component.
   TRedirectReferenceVisitor = Class(TLinkedListVisitor)
   TRedirectReferenceVisitor = Class(TLinkedListVisitor)
     FOld,
     FOld,
@@ -90,7 +90,7 @@ type
     Function Visit(Item : TLinkedListItem) : Boolean; override;
     Function Visit(Item : TLinkedListItem) : Boolean; override;
     Constructor Create(ARoot : TComponent;Const AOld,ANew : String);
     Constructor Create(ARoot : TComponent;Const AOld,ANew : String);
   end;
   end;
-  
+
 var
 var
   NeedResolving : TLinkedList;
   NeedResolving : TLinkedList;
   ResolveSection : TRTLCriticalSection;
   ResolveSection : TRTLCriticalSection;
@@ -100,17 +100,21 @@ Function FindUnresolvedInstance(AInstance: TPersistent) : TUnResolvedInstance;
 
 
 begin
 begin
   Result:=Nil;
   Result:=Nil;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(ResolveSection);
   EnterCriticalSection(ResolveSection);
   Try
   Try
+{$endif}
     If Assigned(NeedResolving) then
     If Assigned(NeedResolving) then
       begin
       begin
       Result:=TUnResolvedInstance(NeedResolving.Root);
       Result:=TUnResolvedInstance(NeedResolving.Root);
       While (Result<>Nil) and (Result.Instance<>AInstance) do
       While (Result<>Nil) and (Result.Instance<>AInstance) do
         Result:=TUnResolvedInstance(Result.Next);
         Result:=TUnResolvedInstance(Result.Next);
       end;
       end;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
   finally
     LeaveCriticalSection(ResolveSection);
     LeaveCriticalSection(ResolveSection);
   end;
   end;
+{$endif}
 end;
 end;
 
 
 Function AddtoResolveList(AInstance: TPersistent) : TUnResolvedInstance;
 Function AddtoResolveList(AInstance: TPersistent) : TUnResolvedInstance;
@@ -119,53 +123,65 @@ begin
   Result:=FindUnresolvedInstance(AInstance);
   Result:=FindUnresolvedInstance(AInstance);
   If (Result=Nil) then
   If (Result=Nil) then
     begin
     begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
     EnterCriticalSection(ResolveSection);
     EnterCriticalSection(ResolveSection);
     Try
     Try
+{$endif}
       If not Assigned(NeedResolving) then
       If not Assigned(NeedResolving) then
         NeedResolving:=TLinkedList.Create(TUnResolvedInstance);
         NeedResolving:=TLinkedList.Create(TUnResolvedInstance);
       Result:=NeedResolving.Add as TUnResolvedInstance;
       Result:=NeedResolving.Add as TUnResolvedInstance;
       Result.Instance:=AInstance;
       Result.Instance:=AInstance;
+{$ifdef FPC_HAS_FEATURE_THREADING}
     finally
     finally
       LeaveCriticalSection(ResolveSection);
       LeaveCriticalSection(ResolveSection);
     end;
     end;
+{$endif}
     end;
     end;
 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);
 Procedure VisitResolveList(V : TLinkedListVisitor);
 
 
 begin
 begin
+{$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalSection(ResolveSection);
   EnterCriticalSection(ResolveSection);
   Try
   Try
+{$endif}
     try
     try
       NeedResolving.Foreach(V);
       NeedResolving.Foreach(V);
     Finally
     Finally
       FreeAndNil(V);
       FreeAndNil(V);
-    end;  
+    end;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   Finally
   Finally
     LeaveCriticalSection(ResolveSection);
     LeaveCriticalSection(ResolveSection);
-  end;  
+  end;
+{$endif}
 end;
 end;
 
 
 procedure GlobalFixupReferences;
 procedure GlobalFixupReferences;
 
 
 begin
 begin
-  If (NeedResolving=Nil) then 
+  If (NeedResolving=Nil) then
     Exit;
     Exit;
+{$ifdef FPC_HAS_FEATURE_THREADING}
   GlobalNameSpace.BeginWrite;
   GlobalNameSpace.BeginWrite;
   try
   try
+{$endif}
     VisitResolveList(TResolveReferenceVisitor.Create);
     VisitResolveList(TResolveReferenceVisitor.Create);
+{$ifdef FPC_HAS_FEATURE_THREADING}
   finally
   finally
     GlobalNameSpace.EndWrite;
     GlobalNameSpace.EndWrite;
   end;
   end;
+{$endif}
 end;
 end;
 
 
 
 
 procedure GetFixupReferenceNames(Root: TComponent; Names: TStrings);
 procedure GetFixupReferenceNames(Root: TComponent; Names: TStrings);
 
 
 begin
 begin
-  If (NeedResolving=Nil) then 
+  If (NeedResolving=Nil) then
     Exit;
     Exit;
   VisitResolveList(TReferenceNamesVisitor.Create(Root,Names));
   VisitResolveList(TReferenceNamesVisitor.Create(Root,Names));
 end;
 end;
@@ -236,7 +252,7 @@ begin
     If Result then
     If Result then
       SetObjectProp(Instance, FPropInfo,C);
       SetObjectProp(Instance, FPropInfo,C);
     end;
     end;
-end; 
+end;
 
 
 Function TUnresolvedReference.RootMatches(ARoot : TComponent) : Boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 Function TUnresolvedReference.RootMatches(ARoot : TComponent) : Boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 
 
@@ -270,7 +286,7 @@ begin
   Result.FRoot:=ARoot;
   Result.FRoot:=ARoot;
 end;
 end;
 
 
-Function TUnResolvedInstance.RootUnresolved : TUnresolvedReference; 
+Function TUnResolvedInstance.RootUnresolved : TUnresolvedReference;
 
 
 begin
 begin
   Result:=Nil;
   Result:=Nil;
@@ -314,7 +330,7 @@ begin
   While (R<>Nil) do
   While (R<>Nil) do
     begin
     begin
     If R.RootMatches(FRoot) then
     If R.RootMatches(FRoot) then
-      If (FList.IndexOf(R.FGlobal)=-1) then 
+      If (FList.IndexOf(R.FGlobal)=-1) then
         FList.Add(R.FGlobal);
         FList.Add(R.FGlobal);
     R:=R.NextRef;
     R:=R.NextRef;
     end;
     end;
@@ -390,7 +406,7 @@ Var
   UI : TUnResolvedInstance;
   UI : TUnResolvedInstance;
   R : TUnresolvedReference;
   R : TUnresolvedReference;
   L : TFPList;
   L : TFPList;
-  
+
 begin
 begin
   UI:=TUnResolvedInstance(Item);
   UI:=TUnResolvedInstance(Item);
   R:=UI.RootUnresolved;
   R:=UI.RootUnresolved;
@@ -434,7 +450,7 @@ begin
   If (List=Nil) then
   If (List=Nil) then
     List:=TFPList.Create;
     List:=TFPList.Create;
   List.Add(Item);
   List.Add(Item);
-end;  
+end;
 
 
 Destructor TBuildListVisitor.Destroy;
 Destructor TBuildListVisitor.Destroy;
 
 
@@ -451,10 +467,10 @@ end;
 
 
 { TResolveReferenceVisitor }
 { TResolveReferenceVisitor }
 
 
-Function TResolveReferenceVisitor.Visit(Item : TLinkedListItem) : Boolean; 
+Function TResolveReferenceVisitor.Visit(Item : TLinkedListItem) : Boolean;
 
 
 begin
 begin
   If TUnResolvedInstance(Item).ResolveReferences then
   If TUnResolvedInstance(Item).ResolveReferences then
     Add(Item);
     Add(Item);
-  Result:=True;  
+  Result:=True;
 end;
 end;

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

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