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

Function incstep

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

** Performs a basic incremental step. The debt and step size are ** converted from bytes to "units of work"; then the function loops ** running single steps until adding that many units of work or ** finishing a cycle (pause state). Finally, it sets the debt that ** controls when next step will be performed. */

Source from the content-addressed store, hash-verified

1655** controls when next step will be performed.
1656*/
1657static void incstep (lua_State *L, global_State *g) {
1658 int stepmul = (getgcparam(g->gcstepmul) | 1); /* avoid division by 0 */
1659 l_mem debt = (g->GCdebt / WORK2MEM) * stepmul;
1660 l_mem stepsize = (g->gcstepsize <= log2maxs(l_mem))
1661 ? ((cast(l_mem, 1) << g->gcstepsize) / WORK2MEM) * stepmul
1662 : MAX_LMEM; /* overflow; keep maximum value */
1663 do { /* repeat until pause or enough "credit" (negative debt) */
1664 lu_mem work = singlestep(L); /* perform one single step */
1665 debt -= work;
1666 } while (debt > -stepsize && g->gcstate != GCSpause);
1667 if (g->gcstate == GCSpause)
1668 setpause(g); /* pause until next cycle */
1669 else {
1670 debt = (debt / stepmul) * WORK2MEM; /* convert 'work units' to bytes */
1671 luaE_setdebt(g, debt);
1672 }
1673}
1674
1675/*
1676** performs a basic GC step if collector is running

Callers 1

luaC_stepFunction · 0.85

Calls 3

singlestepFunction · 0.85
setpauseFunction · 0.85
luaE_setdebtFunction · 0.85

Tested by

no test coverage detected