* 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 -
This commit is contained in:
yury 2007-12-28 14:40:28 +00:00
parent e00bacdcef
commit 0dcad4d822
20 changed files with 45 additions and 52 deletions

View File

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

View File

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

View File

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

View File

@ -298,11 +298,6 @@ 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}

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,16 @@
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
@ -212,13 +221,13 @@ Function SetThreadManager(Const NewTM : TThreadManager) : Boolean;
begin
Result:=True;
If Assigned(CurrentTM.DoneManager) then
Result:=CurrentTM.DoneManager();
If Assigned(fCurrentTM.DoneManager) then
Result:=fCurrentTM.DoneManager();
If Result then
begin
CurrentTM:=NewTM;
If Assigned(CurrentTM.InitManager) then
Result:=CurrentTM.InitManager();
fCurrentTM:=NewTM;
If Assigned(fCurrentTM.InitManager) then
Result:=fCurrentTM.InitManager();
end;
end;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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