| 1523 | |
| 1524 | |
| 1525 | static lu_mem atomic (lua_State *L) { |
| 1526 | global_State *g = G(L); |
| 1527 | lu_mem work = 0; |
| 1528 | GCObject *origweak, *origall; |
| 1529 | GCObject *grayagain = g->grayagain; /* save original list */ |
| 1530 | g->grayagain = NULL; |
| 1531 | lua_assert(g->ephemeron == NULL && g->weak == NULL); |
| 1532 | lua_assert(!iswhite(g->mainthread)); |
| 1533 | g->gcstate = GCSatomic; |
| 1534 | markobject(g, L); /* mark running thread */ |
| 1535 | /* registry and global metatables may be changed by API */ |
| 1536 | markvalue(g, &g->l_registry); |
| 1537 | markmt(g); /* mark global metatables */ |
| 1538 | work += propagateall(g); /* empties 'gray' list */ |
| 1539 | /* remark occasional upvalues of (maybe) dead threads */ |
| 1540 | work += remarkupvals(g); |
| 1541 | work += propagateall(g); /* propagate changes */ |
| 1542 | g->gray = grayagain; |
| 1543 | work += propagateall(g); /* traverse 'grayagain' list */ |
| 1544 | convergeephemerons(g); |
| 1545 | /* at this point, all strongly accessible objects are marked. */ |
| 1546 | /* Clear values from weak tables, before checking finalizers */ |
| 1547 | clearbyvalues(g, g->weak, NULL); |
| 1548 | clearbyvalues(g, g->allweak, NULL); |
| 1549 | origweak = g->weak; origall = g->allweak; |
| 1550 | separatetobefnz(g, 0); /* separate objects to be finalized */ |
| 1551 | work += markbeingfnz(g); /* mark objects that will be finalized */ |
| 1552 | work += propagateall(g); /* remark, to propagate 'resurrection' */ |
| 1553 | convergeephemerons(g); |
| 1554 | /* at this point, all resurrected objects are marked. */ |
| 1555 | /* remove dead objects from weak tables */ |
| 1556 | clearbykeys(g, g->ephemeron); /* clear keys from all ephemeron tables */ |
| 1557 | clearbykeys(g, g->allweak); /* clear keys from all 'allweak' tables */ |
| 1558 | /* clear values from resurrected weak tables */ |
| 1559 | clearbyvalues(g, g->weak, origweak); |
| 1560 | clearbyvalues(g, g->allweak, origall); |
| 1561 | luaS_clearcache(g); |
| 1562 | g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ |
| 1563 | lua_assert(g->gray == NULL); |
| 1564 | return work; /* estimate of slots marked by 'atomic' */ |
| 1565 | } |
| 1566 | |
| 1567 | |
| 1568 | static int sweepstep (lua_State *L, global_State *g, |
no test coverage detected