2
0
Эх сурвалжийг харах

* revert r9557, the performance impact is to big for an academic corner
case optimziation

git-svn-id: trunk@9603 -

peter 17 жил өмнө
parent
commit
5acb3649df

+ 1 - 0
rtl/amiga/system.pp

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

+ 1 - 0
rtl/beos/system.pp

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

+ 2 - 0
rtl/bsd/system.pp

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

+ 5 - 0
rtl/embedded/system.pp

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

+ 2 - 0
rtl/emx/system.pas

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

+ 2 - 0
rtl/gba/system.pp

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

+ 3 - 0
rtl/go32v2/system.pp

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

+ 14 - 30
rtl/inc/heap.inc

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

+ 6 - 15
rtl/inc/thread.inc

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

+ 2 - 0
rtl/linux/system.pp

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

+ 1 - 0
rtl/macos/system.pp

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

+ 1 - 0
rtl/morphos/system.pp

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

+ 2 - 0
rtl/nds/system.pp

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

+ 1 - 0
rtl/netware/system.pp

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

+ 1 - 0
rtl/netwlibc/system.pp

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

+ 1 - 0
rtl/os2/system.pas

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

+ 1 - 0
rtl/solaris/system.pp

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

+ 2 - 0
rtl/win32/system.pp

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

+ 2 - 0
rtl/win64/system.pp

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

+ 2 - 0
rtl/wince/system.pp

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