Pārlūkot izejas kodu

* Implemented late thread manager initialization. Thread manager code is not included to executable if thread stuff are not used. WinCE executable size is reduced by 4KB, Win32 executable size is reduced by 3KB. No testsuite regressions.

git-svn-id: trunk@9557 -
yury 17 gadi atpakaļ
vecāks
revīzija
0dcad4d822

+ 0 - 1
rtl/amiga/system.pp

@@ -385,7 +385,6 @@ begin
   InOutRes:=0;
   InOutRes:=0;
 { Arguments }
 { Arguments }
   GenerateArgs;
   GenerateArgs;
-  InitSystemThreads;
   initvariantmanager;
   initvariantmanager;
   initwidestringmanager;
   initwidestringmanager;
 end.
 end.

+ 0 - 1
rtl/beos/system.pp

@@ -411,7 +411,6 @@ begin
   SysInitStdIO;
   SysInitStdIO;
 { Reset IO Error }
 { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
-  InitSystemThreads;
 {$ifdef HASVARIANT}
 {$ifdef HASVARIANT}
   initvariantmanager;
   initvariantmanager;
 {$endif HASVARIANT}
 {$endif HASVARIANT}

+ 0 - 2
rtl/bsd/system.pp

@@ -294,8 +294,6 @@ Begin
   InOutRes:=0;
   InOutRes:=0;
   { Arguments }
   { Arguments }
   SetupCmdLine;
   SetupCmdLine;
-  { threading }
-  InitSystemThreads;
   initvariantmanager;
   initvariantmanager;
   initwidestringmanager;
   initwidestringmanager;
 End.
 End.

+ 0 - 5
rtl/embedded/system.pp

@@ -298,11 +298,6 @@ begin
   InOutRes:=0;
   InOutRes:=0;
 {$endif FPC_HAS_FEATURE_CONSOLEIO}
 {$endif FPC_HAS_FEATURE_CONSOLEIO}
 
 
-{$ifdef FPC_HAS_FEATURE_THREADING}
-  { threading }
-  InitSystemThreads;
-{$endif FPC_HAS_FEATURE_THREADING}
-
 {$ifdef FPC_HAS_FEATURE_VARIANTS}
 {$ifdef FPC_HAS_FEATURE_VARIANTS}
   initvariantmanager;
   initvariantmanager;
 {$endif FPC_HAS_FEATURE_VARIANTS}
 {$endif FPC_HAS_FEATURE_VARIANTS}

+ 0 - 2
rtl/emx/system.pas

@@ -577,8 +577,6 @@ begin
     { no I/O-Error }
     { no I/O-Error }
     inoutres:=0;
     inoutres:=0;
 
 
-    InitSystemThreads;
-
     InitVariantManager;
     InitVariantManager;
 
 
 {$ifdef HASWIDESTRING}
 {$ifdef HASWIDESTRING}

+ 0 - 2
rtl/gba/system.pp

@@ -146,7 +146,5 @@ begin
   SysInitStdIO;
   SysInitStdIO;
 { Reset IO Error }
 { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
-{ Arguments }
-  InitSystemThreads;
   initvariantmanager;
   initvariantmanager;
 end.
 end.

+ 0 - 3
rtl/go32v2/system.pp

@@ -656,9 +656,6 @@ Begin
    AllFilesMask := '*.*';
    AllFilesMask := '*.*';
 { Reset IO Error }
 { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
-{$ifdef FPC_HAS_FEATURE_THREADING}
-  InitSystemThreads;
-{$endif}
 {$ifdef  EXCEPTIONS_IN_SYSTEM}
 {$ifdef  EXCEPTIONS_IN_SYSTEM}
   InitDPMIExcp;
   InitDPMIExcp;
   InstallDefaultHandlers;
   InstallDefaultHandlers;

+ 30 - 14
rtl/inc/heap.inc

@@ -395,6 +395,22 @@ procedure finish_waitvarlist(loc_freelists: pfreelists); forward;
 function  try_finish_waitfixedlist(loc_freelists: pfreelists): boolean; forward;
 function  try_finish_waitfixedlist(loc_freelists: pfreelists): boolean; forward;
 procedure try_finish_waitvarlist(loc_freelists: pfreelists); forward;
 procedure try_finish_waitvarlist(loc_freelists: pfreelists); forward;
 
 
+
+var
+  fTM: TThreadManager; external name 'fCurrentTM';
+
+procedure do_heap_lock;
+begin
+  if Assigned(fTM.EnterCriticalSection) then
+    fTM.EnterCriticalSection(heap_lock);
+end;
+
+procedure do_heap_unlock;
+begin
+  if Assigned(fTM.LeaveCriticalSection) then
+    fTM.LeaveCriticalSection(heap_lock);
+end;
+
 {*****************************************************************************
 {*****************************************************************************
                                 List adding/removal
                                 List adding/removal
 *****************************************************************************}
 *****************************************************************************}
@@ -734,7 +750,7 @@ begin
   if not assigned(poc) and (assigned(orphaned_freelists.waitfixed) 
   if not assigned(poc) and (assigned(orphaned_freelists.waitfixed) 
       or assigned(orphaned_freelists.waitvar) or (orphaned_freelists.oscount > 0)) then
       or assigned(orphaned_freelists.waitvar) or (orphaned_freelists.oscount > 0)) then
     begin
     begin
-      entercriticalsection(heap_lock);
+      do_heap_lock;
       finish_waitfixedlist(@orphaned_freelists);
       finish_waitfixedlist(@orphaned_freelists);
       finish_waitvarlist(@orphaned_freelists);
       finish_waitvarlist(@orphaned_freelists);
       if orphaned_freelists.oscount > 0 then
       if orphaned_freelists.oscount > 0 then
@@ -758,7 +774,7 @@ begin
               loc_freelists^.oslist_all := poc;
               loc_freelists^.oslist_all := poc;
             end;
             end;
         end;
         end;
-      leavecriticalsection(heap_lock);
+      do_heap_unlock;
     end;
     end;
   if poc = nil then
   if poc = nil then
     begin
     begin
@@ -1019,18 +1035,18 @@ end;
 
 
 procedure waitfree_fixed(pmc: pmemchunk_fixed; poc: poschunk);
 procedure waitfree_fixed(pmc: pmemchunk_fixed; poc: poschunk);
 begin
 begin
-  entercriticalsection(heap_lock);
+  do_heap_lock;
   pmc^.next_fixed := poc^.freelists^.waitfixed;
   pmc^.next_fixed := poc^.freelists^.waitfixed;
   poc^.freelists^.waitfixed := pmc;
   poc^.freelists^.waitfixed := pmc;
-  leavecriticalsection(heap_lock);
+  do_heap_unlock;
 end;
 end;
 
 
 procedure waitfree_var(pmcv: pmemchunk_var);
 procedure waitfree_var(pmcv: pmemchunk_var);
 begin
 begin
-  entercriticalsection(heap_lock);
+  do_heap_lock;
   pmcv^.next_var := pmcv^.freelists^.waitvar;
   pmcv^.next_var := pmcv^.freelists^.waitvar;
   pmcv^.freelists^.waitvar := pmcv;
   pmcv^.freelists^.waitvar := pmcv;
-  leavecriticalsection(heap_lock);
+  do_heap_unlock;
 end;
 end;
 
 
 function SysFreeMem_Fixed(loc_freelists: pfreelists; pmc: pmemchunk_fixed): ptruint;
 function SysFreeMem_Fixed(loc_freelists: pfreelists; pmc: pmemchunk_fixed): ptruint;
@@ -1141,9 +1157,9 @@ function try_finish_waitfixedlist(loc_freelists: pfreelists): boolean;
 begin
 begin
   if loc_freelists^.waitfixed = nil then 
   if loc_freelists^.waitfixed = nil then 
     exit(false);
     exit(false);
-  entercriticalsection(heap_lock);
+  do_heap_lock;
   finish_waitfixedlist(loc_freelists);
   finish_waitfixedlist(loc_freelists);
-  leavecriticalsection(heap_lock);
+  do_heap_unlock;
   result := true;
   result := true;
 end;
 end;
 
 
@@ -1165,9 +1181,9 @@ procedure try_finish_waitvarlist(loc_freelists: pfreelists);
 begin
 begin
   if loc_freelists^.waitvar = nil then 
   if loc_freelists^.waitvar = nil then 
     exit;
     exit;
-  entercriticalsection(heap_lock);
+  do_heap_lock;
   finish_waitvarlist(loc_freelists);
   finish_waitvarlist(loc_freelists);
-  leavecriticalsection(heap_lock);
+  do_heap_unlock;
 end;
 end;
 
 
 {*****************************************************************************
 {*****************************************************************************
@@ -1431,7 +1447,7 @@ begin
   loc_freelists := @freelists;
   loc_freelists := @freelists;
   if main_relo_freelists <> nil then
   if main_relo_freelists <> nil then
   begin
   begin
-    entercriticalsection(heap_lock);
+    do_heap_lock;
     finish_waitfixedlist(loc_freelists);
     finish_waitfixedlist(loc_freelists);
     finish_waitvarlist(loc_freelists);
     finish_waitvarlist(loc_freelists);
 {$ifdef HAS_SYSOSFREE}
 {$ifdef HAS_SYSOSFREE}
@@ -1463,9 +1479,9 @@ begin
         orphaned_freelists.oslist_all := loc_freelists^.oslist_all;
         orphaned_freelists.oslist_all := loc_freelists^.oslist_all;
       end;
       end;
     end;
     end;
-    leavecriticalsection(heap_lock);
-    if main_relo_freelists = loc_freelists then
-      donecriticalsection(heap_lock);
+    do_heap_unlock;
+    if (main_relo_freelists = loc_freelists) and Assigned(fTM.DoneCriticalSection) then
+      fTM.DoneCriticalSection(heap_lock);
   end;
   end;
 {$ifdef SHOW_MEM_USAGE}
 {$ifdef SHOW_MEM_USAGE}
   writeln('Max heap used/size: ', loc_freelists^.internal_status.maxheapused, '/', 
   writeln('Max heap used/size: ', loc_freelists^.internal_status.maxheapused, '/', 

+ 15 - 6
rtl/inc/thread.inc

@@ -15,7 +15,16 @@
 
 
 
 
 Var
 Var
-  CurrentTM : TThreadManager;
+  fCurrentTM : TThreadManager; public;
+  
+    Procedure InitSystemThreads; forward;
+    
+    function CurrentTM : TThreadManager;
+      begin
+        if not Assigned(fCurrentTM.BeginThread) then
+          InitSystemThreads;
+        Result:=fCurrentTM;
+      end;
 
 
 {*****************************************************************************
 {*****************************************************************************
                            Threadvar initialization
                            Threadvar initialization
@@ -212,13 +221,13 @@ Function SetThreadManager(Const NewTM : TThreadManager) : Boolean;
 
 
 begin
 begin
   Result:=True;
   Result:=True;
-  If Assigned(CurrentTM.DoneManager) then
-    Result:=CurrentTM.DoneManager();
+  If Assigned(fCurrentTM.DoneManager) then
+    Result:=fCurrentTM.DoneManager();
   If Result then
   If Result then
     begin
     begin
-    CurrentTM:=NewTM;
-    If Assigned(CurrentTM.InitManager) then
-      Result:=CurrentTM.InitManager();
+    fCurrentTM:=NewTM;
+    If Assigned(fCurrentTM.InitManager) then
+      Result:=fCurrentTM.InitManager();
     end;
     end;
 end;
 end;
 
 

+ 0 - 2
rtl/linux/system.pp

@@ -333,8 +333,6 @@ begin
   SysInitExecPath;
   SysInitExecPath;
   { Reset IO Error }
   { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
-  { threading }
-  InitSystemThreads;
   initvariantmanager;
   initvariantmanager;
   initwidestringmanager;
   initwidestringmanager;
 end.
 end.

+ 0 - 1
rtl/macos/system.pp

@@ -553,7 +553,6 @@ begin
   { Reset IO Error }
   { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
   errno:=0;
   errno:=0;
-  InitSystemThreads;
   initvariantmanager;
   initvariantmanager;
   initwidestringmanager;
   initwidestringmanager;
 
 

+ 0 - 1
rtl/morphos/system.pp

@@ -417,7 +417,6 @@ begin
   InOutRes:=0;
   InOutRes:=0;
 { Arguments }
 { Arguments }
   GenerateArgs;
   GenerateArgs;
-  InitSystemThreads;
   initvariantmanager;
   initvariantmanager;
   initwidestringmanager;
   initwidestringmanager;
 end.
 end.

+ 0 - 2
rtl/nds/system.pp

@@ -173,7 +173,5 @@ begin
   SysInitStdIO;
   SysInitStdIO;
 { Reset IO Error }
 { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
-{ Arguments }
-  InitSystemThreads;
   initvariantmanager;
   initvariantmanager;
 end.
 end.

+ 0 - 1
rtl/netware/system.pp

@@ -476,7 +476,6 @@ Begin
   IsLibrary := FALSE;
   IsLibrary := FALSE;
   IsConsole := TRUE;
   IsConsole := TRUE;
   ExitCode  := 0;
   ExitCode  := 0;
-  InitSystemThreads;
   initvariantmanager;
   initvariantmanager;
   initwidestringmanager;
   initwidestringmanager;
 End.
 End.

+ 0 - 1
rtl/netwlibc/system.pp

@@ -546,7 +546,6 @@ Begin
 {Delphi Compatible}
 {Delphi Compatible}
   IsConsole := TRUE;
   IsConsole := TRUE;
   ExitCode  := 0;
   ExitCode  := 0;
-  InitSystemThreads;
   initvariantmanager;
   initvariantmanager;
   initwidestringmanager;
   initwidestringmanager;
 End.
 End.

+ 0 - 1
rtl/os2/system.pas

@@ -1189,7 +1189,6 @@ begin
     DefaultCreator := '';
     DefaultCreator := '';
     DefaultFileType := '';
     DefaultFileType := '';
 
 
-    InitSystemThreads;
     InitVariantManager;
     InitVariantManager;
 
 
 {$ifdef HASWIDESTRING}
 {$ifdef HASWIDESTRING}

+ 0 - 1
rtl/solaris/system.pp

@@ -229,7 +229,6 @@ Begin
   InOutRes:=0;
   InOutRes:=0;
 { Arguments }
 { Arguments }
   SetupCmdLine;
   SetupCmdLine;
-  InitSystemThreads;
   initvariantmanager;
   initvariantmanager;
   initwidestringmanager;
   initwidestringmanager;
 End.
 End.

+ 0 - 2
rtl/win32/system.pp

@@ -1219,8 +1219,6 @@ begin
   { Reset IO Error }
   { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
   ProcessID := GetCurrentProcessID;
   ProcessID := GetCurrentProcessID;
-  { threading }
-  InitSystemThreads;
   { Reset internal error variable }
   { Reset internal error variable }
   errno:=0;
   errno:=0;
   initvariantmanager;
   initvariantmanager;

+ 0 - 2
rtl/win64/system.pp

@@ -1170,8 +1170,6 @@ begin
   { Reset IO Error }
   { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
   ProcessID := GetCurrentProcessID;
   ProcessID := GetCurrentProcessID;
-  { threading }
-  InitSystemThreads;
   { Reset internal error variable }
   { Reset internal error variable }
   errno:=0;
   errno:=0;
   initvariantmanager;
   initvariantmanager;

+ 0 - 2
rtl/wince/system.pp

@@ -1812,8 +1812,6 @@ initialization
   { Reset IO Error }
   { Reset IO Error }
   InOutRes:=0;
   InOutRes:=0;
   ProcessID := GetCurrentProcessID;
   ProcessID := GetCurrentProcessID;
-  { threading }
-  InitSystemThreads;
   { Reset internal error variable }
   { Reset internal error variable }
   errno:=0;
   errno:=0;
   initvariantmanager;
   initvariantmanager;