|
@@ -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, '/',
|