mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-13 19:09:30 +01:00
heap manager: initialize critical sections properly
git-svn-id: trunk@7412 -
This commit is contained in:
parent
df7ad9f68d
commit
6c85fcb157
@ -821,6 +821,7 @@ begin
|
|||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{*****************************************************************************
|
{*****************************************************************************
|
||||||
SysGetMem
|
SysGetMem
|
||||||
*****************************************************************************}
|
*****************************************************************************}
|
||||||
@ -1350,22 +1351,42 @@ end;
|
|||||||
{$if not(defined(gba)) and not(defined(nds))}
|
{$if not(defined(gba)) and not(defined(nds))}
|
||||||
{ This function will initialize the Heap manager and need to be called from
|
{ This function will initialize the Heap manager and need to be called from
|
||||||
the initialization of the system unit }
|
the initialization of the system unit }
|
||||||
procedure InitHeap;
|
procedure InitHeapThread;
|
||||||
|
var
|
||||||
|
loc_freelists: pfreelists;
|
||||||
begin
|
begin
|
||||||
fillchar(freelists,sizeof(tfreelists),0);
|
loc_freelists := @freelists;
|
||||||
{ main freelist will be copied in memory }
|
fillchar(loc_freelists^,sizeof(tfreelists),0);
|
||||||
main_orig_freelists := @freelists;
|
initcriticalsection(loc_freelists^.lockfixed);
|
||||||
|
initcriticalsection(loc_freelists^.lockvar);
|
||||||
{$ifdef DUMP_MEM_USAGE}
|
{$ifdef DUMP_MEM_USAGE}
|
||||||
fillchar(sizeusage,sizeof(sizeusage),0);
|
fillchar(sizeusage,sizeof(sizeusage),0);
|
||||||
fillchar(maxsizeusage,sizeof(sizeusage),0);
|
fillchar(maxsizeusage,sizeof(sizeusage),0);
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure InitHeap;
|
||||||
|
var
|
||||||
|
loc_freelists: pfreelists;
|
||||||
|
begin
|
||||||
|
{ we cannot initialize the locks here yet, thread support is
|
||||||
|
not loaded yet }
|
||||||
|
loc_freelists := @freelists;
|
||||||
|
fillchar(loc_freelists^,sizeof(tfreelists),0);
|
||||||
|
{ main freelist will be copied in memory }
|
||||||
|
main_orig_freelists := loc_freelists;
|
||||||
|
end;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
procedure RelocateHeap;
|
procedure RelocateHeap;
|
||||||
|
var
|
||||||
|
loc_freelists: pfreelists;
|
||||||
begin
|
begin
|
||||||
{ this function should be called in main thread context }
|
{ this function should be called in main thread context }
|
||||||
main_relo_freelists := @freelists;
|
loc_freelists := @freelists;
|
||||||
|
main_relo_freelists := loc_freelists;
|
||||||
|
initcriticalsection(loc_freelists^.lockfixed);
|
||||||
|
initcriticalsection(loc_freelists^.lockvar);
|
||||||
if MemoryManager.RelocateHeap <> nil then
|
if MemoryManager.RelocateHeap <> nil then
|
||||||
MemoryManager.RelocateHeap();
|
MemoryManager.RelocateHeap();
|
||||||
end;
|
end;
|
||||||
@ -1379,6 +1400,11 @@ begin
|
|||||||
loc_freelists := @freelists;
|
loc_freelists := @freelists;
|
||||||
finish_waitfixedlist(loc_freelists);
|
finish_waitfixedlist(loc_freelists);
|
||||||
finish_waitvarlist(loc_freelists);
|
finish_waitvarlist(loc_freelists);
|
||||||
|
if main_relo_freelists <> nil then
|
||||||
|
begin
|
||||||
|
donecriticalsection(loc_freelists^.lockfixed);
|
||||||
|
donecriticalsection(loc_freelists^.lockvar);
|
||||||
|
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, '/',
|
||||||
loc_freelists^.internal_status.maxheapsize);
|
loc_freelists^.internal_status.maxheapsize);
|
||||||
|
|||||||
@ -25,7 +25,7 @@ Var
|
|||||||
begin
|
begin
|
||||||
SysResetFPU;
|
SysResetFPU;
|
||||||
{ initialize this thread's heap }
|
{ initialize this thread's heap }
|
||||||
InitHeap;
|
InitHeapThread;
|
||||||
if MemoryManager.InitThread <> nil then
|
if MemoryManager.InitThread <> nil then
|
||||||
MemoryManager.InitThread();
|
MemoryManager.InitThread();
|
||||||
{ ExceptAddrStack and ExceptObjectStack are threadvars }
|
{ ExceptAddrStack and ExceptObjectStack are threadvars }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user