Skip to content

Commit

Permalink
[GC] Make sure we don't take a GC lock for grow/shrink calls without …
Browse files Browse the repository at this point in the history
…entering a busy state. (#414)
  • Loading branch information
schveiguy authored Dec 23, 2024
1 parent 3b70ab1 commit b0ca296
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions sdlib/d/gc/tcache.d
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ public:
auto npages = getPageCount(size);

if (epages < npages) {
if (!pd.arena.growLarge(emap, e, npages)) {
if (!growLarge(pd, npages)) {
goto LargeResizeFailed;
}

triggerAllocationEvent((npages - epages) * PageSize);
} else if (epages > npages) {
if (!pd.arena.shrinkLarge(emap, e, npages)) {
if (!shrinkLarge(pd, npages)) {
goto LargeResizeFailed;
}

Expand Down Expand Up @@ -708,7 +708,7 @@ private:

auto npages = getPageCount(newCapacity);
if (epages < npages) {
if (!pd.arena.growLarge(emap, e, npages)) {
if (!growLarge(pd, npages)) {
return false;
}

Expand All @@ -722,6 +722,20 @@ private:
return true;
}

bool growLarge(PageDescriptor pd, uint npages) {
state.enterBusyState();
scope(exit) state.exitBusyState();

return pd.arena.growLarge(emap, pd.extent, npages);
}

bool shrinkLarge(PageDescriptor pd, uint npages) {
state.enterBusyState();
scope(exit) state.exitBusyState();

return pd.arena.shrinkLarge(emap, pd.extent, npages);
}

auto getPageDescriptor(void* ptr) {
auto pd = maybeGetPageDescriptor(ptr);
assert(pd.extent !is null);
Expand Down

0 comments on commit b0ca296

Please sign in to comment.