MCPcopy Create free account
hub / github.com/DFHack/dfhack / atomic

Function atomic

depends/lua/src/lgc.c:982–1026  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

980
981
982static l_mem atomic (lua_State *L) {
983 global_State *g = G(L);
984 l_mem work;
985 GCObject *origweak, *origall;
986 GCObject *grayagain = g->grayagain; /* save original list */
987 lua_assert(g->ephemeron == NULL && g->weak == NULL);
988 lua_assert(!iswhite(g->mainthread));
989 g->gcstate = GCSinsideatomic;
990 g->GCmemtrav = 0; /* start counting work */
991 markobject(g, L); /* mark running thread */
992 /* registry and global metatables may be changed by API */
993 markvalue(g, &g->l_registry);
994 markmt(g); /* mark global metatables */
995 /* remark occasional upvalues of (maybe) dead threads */
996 remarkupvals(g);
997 propagateall(g); /* propagate changes */
998 work = g->GCmemtrav; /* stop counting (do not recount 'grayagain') */
999 g->gray = grayagain;
1000 propagateall(g); /* traverse 'grayagain' list */
1001 g->GCmemtrav = 0; /* restart counting */
1002 convergeephemerons(g);
1003 /* at this point, all strongly accessible objects are marked. */
1004 /* Clear values from weak tables, before checking finalizers */
1005 clearvalues(g, g->weak, NULL);
1006 clearvalues(g, g->allweak, NULL);
1007 origweak = g->weak; origall = g->allweak;
1008 work += g->GCmemtrav; /* stop counting (objects being finalized) */
1009 separatetobefnz(g, 0); /* separate objects to be finalized */
1010 g->gcfinnum = 1; /* there may be objects to be finalized */
1011 markbeingfnz(g); /* mark objects that will be finalized */
1012 propagateall(g); /* remark, to propagate 'resurrection' */
1013 g->GCmemtrav = 0; /* restart counting */
1014 convergeephemerons(g);
1015 /* at this point, all resurrected objects are marked. */
1016 /* remove dead objects from weak tables */
1017 clearkeys(g, g->ephemeron, NULL); /* clear keys from all ephemeron tables */
1018 clearkeys(g, g->allweak, NULL); /* clear keys from all 'allweak' tables */
1019 /* clear values from resurrected weak tables */
1020 clearvalues(g, g->weak, origweak);
1021 clearvalues(g, g->allweak, origall);
1022 luaS_clearcache(g);
1023 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */
1024 work += g->GCmemtrav; /* complete counting */
1025 return work; /* estimate of memory marked by 'atomic' */
1026}
1027
1028
1029static lu_mem sweepstep (lua_State *L, global_State *g,

Callers 1

singlestepFunction · 0.85

Calls 9

markmtFunction · 0.85
remarkupvalsFunction · 0.85
propagateallFunction · 0.85
convergeephemeronsFunction · 0.85
clearvaluesFunction · 0.85
separatetobefnzFunction · 0.85
markbeingfnzFunction · 0.85
clearkeysFunction · 0.85
luaS_clearcacheFunction · 0.85

Tested by

no test coverage detected