Skip to main content

luaur_vm/functions/
atomic.rs

1use crate::functions::cleartable::cleartable;
2use crate::functions::clearupvals::clearupvals;
3use crate::functions::markmt::markmt;
4use crate::functions::propagateall::propagateall;
5use crate::functions::remarkupvals::remarkupvals;
6use crate::macros::gc_satomic::GCSatomic;
7use crate::macros::gc_satomic::GCSsweep;
8use crate::macros::markobject::markobject;
9use crate::macros::otherwhite::otherwhite;
10use crate::records::gc_object::GCObject;
11use crate::type_aliases::lua_state::lua_State;
12use luaur_common::macros::luau_assert::LUAU_ASSERT;
13
14#[allow(non_snake_case)]
15pub unsafe fn atomic(l: *mut lua_State) -> usize {
16    let g = (*l).global;
17    LUAU_ASSERT!((*g).gcstate as i32 == GCSatomic);
18
19    let mut work = 0usize;
20
21    work += remarkupvals(g);
22    work += propagateall(g);
23
24    (*g).gray = (*g).weak;
25    (*g).weak = core::ptr::null_mut();
26    LUAU_ASSERT!(!crate::iswhite!((*g).mainthread as *mut GCObject));
27    markobject!(g, l);
28    markmt(g);
29    work += propagateall(g);
30
31    (*g).gray = (*g).grayagain;
32    (*g).grayagain = core::ptr::null_mut();
33    work += propagateall(g);
34
35    work += cleartable(l, (*g).weak);
36    (*g).weak = core::ptr::null_mut();
37
38    work += clearupvals(l);
39
40    (*g).currentwhite = otherwhite!(g) as u8;
41    (*g).sweepgcopage = (*g).allgcopages;
42    (*g).gcstate = GCSsweep as u8;
43
44    work
45}