| 1414 | |
| 1415 | |
| 1416 | static lu_mem atomic (lua_State *L) { |
| 1417 | global_State *g = G(L); |
| 1418 | lu_mem work = 0; |
| 1419 | GCObject *origweak, *origall; |
| 1420 | GCObject *grayagain = g->grayagain; /* save original list */ |
| 1421 | g->grayagain = NULL; |
| 1422 | lua_assert(g->ephemeron == NULL && g->weak == NULL); |
| 1423 | lua_assert(!iswhite(g->mainthread)); |
| 1424 | g->gcstate = GCSatomic; |
| 1425 | markobject(g, L); /* mark running thread */ |
| 1426 | /* registry and global metatables may be changed by API */ |
| 1427 | markvalue(g, &g->l_registry); |
| 1428 | markmt(g); /* mark global metatables */ |
| 1429 | work += propagateall(g); /* empties 'gray' list */ |
| 1430 | /* remark occasional upvalues of (maybe) dead threads */ |
| 1431 | work += remarkupvals(g); |
| 1432 | work += propagateall(g); /* propagate changes */ |
| 1433 | g->gray = grayagain; |
| 1434 | work += propagateall(g); /* traverse 'grayagain' list */ |
| 1435 | convergeephemerons(g); |
| 1436 | /* at this point, all strongly accessible objects are marked. */ |
| 1437 | /* Clear values from weak tables, before checking finalizers */ |
| 1438 | clearbyvalues(g, g->weak, NULL); |
| 1439 | clearbyvalues(g, g->allweak, NULL); |
| 1440 | origweak = g->weak; origall = g->allweak; |
| 1441 | separatetobefnz(g, 0); /* separate objects to be finalized */ |
| 1442 | work += markbeingfnz(g); /* mark objects that will be finalized */ |
| 1443 | work += propagateall(g); /* remark, to propagate 'resurrection' */ |
| 1444 | convergeephemerons(g); |
| 1445 | /* at this point, all resurrected objects are marked. */ |
| 1446 | /* remove dead objects from weak tables */ |
| 1447 | clearbykeys(g, g->ephemeron); /* clear keys from all ephemeron tables */ |
| 1448 | clearbykeys(g, g->allweak); /* clear keys from all 'allweak' tables */ |
| 1449 | /* clear values from resurrected weak tables */ |
| 1450 | clearbyvalues(g, g->weak, origweak); |
| 1451 | clearbyvalues(g, g->allweak, origall); |
| 1452 | luaS_clearcache(g); |
| 1453 | g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ |
| 1454 | lua_assert(g->gray == NULL); |
| 1455 | return work; /* estimate of slots marked by 'atomic' */ |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | static int sweepstep (lua_State *L, global_State *g, |
no test coverage detected