** 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. */
| 1665 | ** controls when next step will be performed. |
| 1666 | */ |
| 1667 | static void incstep (lua_State *L, global_State *g) { |
| 1668 | int stepmul = (getgcparam(g->gcstepmul) | 1); /* avoid division by 0 */ |
| 1669 | l_mem debt = (g->GCdebt / WORK2MEM) * stepmul; |
| 1670 | l_mem stepsize = (g->gcstepsize <= log2maxs(l_mem)) |
| 1671 | ? ((cast(l_mem, 1) << g->gcstepsize) / WORK2MEM) * stepmul |
| 1672 | : MAX_LMEM; /* overflow; keep maximum value */ |
| 1673 | do { /* repeat until pause or enough "credit" (negative debt) */ |
| 1674 | lu_mem work = singlestep(L); /* perform one single step */ |
| 1675 | debt -= work; |
| 1676 | } while (debt > -stepsize && g->gcstate != GCSpause); |
| 1677 | if (g->gcstate == GCSpause) |
| 1678 | setpause(g); /* pause until next cycle */ |
| 1679 | else { |
| 1680 | debt = (debt / stepmul) * WORK2MEM; /* convert 'work units' to bytes */ |
| 1681 | luaE_setdebt(g, debt); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | /* |
| 1686 | ** Performs a basic GC step if collector is running. (If collector is |
no test coverage detected