MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / singlestep

Function singlestep

3rd/lua-5.4.3/src/lgc.c:1576–1636  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1574
1575
1576static lu_mem singlestep (lua_State *L) {
1577 global_State *g = G(L);
1578 lu_mem work;
1579 lua_assert(!g->gcstopem); /* collector is not reentrant */
1580 g->gcstopem = 1; /* no emergency collections while collecting */
1581 switch (g->gcstate) {
1582 case GCSpause: {
1583 restartcollection(g);
1584 g->gcstate = GCSpropagate;
1585 work = 1;
1586 break;
1587 }
1588 case GCSpropagate: {
1589 if (g->gray == NULL) { /* no more gray objects? */
1590 g->gcstate = GCSenteratomic; /* finish propagate phase */
1591 work = 0;
1592 }
1593 else
1594 work = propagatemark(g); /* traverse one gray object */
1595 break;
1596 }
1597 case GCSenteratomic: {
1598 work = atomic(L); /* work is what was traversed by 'atomic' */
1599 entersweep(L);
1600 g->GCestimate = gettotalbytes(g); /* first estimate */;
1601 break;
1602 }
1603 case GCSswpallgc: { /* sweep "regular" objects */
1604 work = sweepstep(L, g, GCSswpfinobj, &g->finobj);
1605 break;
1606 }
1607 case GCSswpfinobj: { /* sweep objects with finalizers */
1608 work = sweepstep(L, g, GCSswptobefnz, &g->tobefnz);
1609 break;
1610 }
1611 case GCSswptobefnz: { /* sweep objects to be finalized */
1612 work = sweepstep(L, g, GCSswpend, NULL);
1613 break;
1614 }
1615 case GCSswpend: { /* finish sweeps */
1616 checkSizes(L, g);
1617 g->gcstate = GCScallfin;
1618 work = 0;
1619 break;
1620 }
1621 case GCScallfin: { /* call remaining finalizers */
1622 if (g->tobefnz && !g->gcemergency) {
1623 g->gcstopem = 0; /* ok collections during finalizers */
1624 work = runafewfinalizers(L, GCFINMAX) * GCFINALIZECOST;
1625 }
1626 else { /* emergency mode or no more finalizers */
1627 g->gcstate = GCSpause; /* finish collection */
1628 work = 0;
1629 }
1630 break;
1631 }
1632 default: lua_assert(0); return 0;
1633 }

Callers 2

luaC_runtilstateFunction · 0.85
incstepFunction · 0.85

Calls 7

restartcollectionFunction · 0.85
propagatemarkFunction · 0.85
atomicFunction · 0.85
entersweepFunction · 0.85
sweepstepFunction · 0.85
checkSizesFunction · 0.85
runafewfinalizersFunction · 0.85

Tested by

no test coverage detected