summaryrefslogtreecommitdiff
path: root/src/lua51/lgc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua51/lgc.h')
-rw-r--r--src/lua51/lgc.h28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/lua51/lgc.h b/src/lua51/lgc.h
index 5a8dc60..9fa686a 100644
--- a/src/lua51/lgc.h
+++ b/src/lua51/lgc.h
@@ -14,11 +14,11 @@
/*
** Possible states of the Garbage Collector
*/
-#define GCSpause 0
-#define GCSpropagate 1
-#define GCSsweepstring 2
-#define GCSsweep 3
-#define GCSfinalize 4
+#define GCSpause 0 // 暂停
+#define GCSpropagate 1 // 扫描,正在遍历灰色节点,检查引用情况
+#define GCSsweepstring 2 // 字符串回收阶段
+#define GCSsweep 3 // 除了字符串的其他对象的回收阶段
+#define GCSfinalize 4 // 终止阶段
/*
@@ -51,15 +51,15 @@
*/
-#define WHITE0BIT 0
-#define WHITE1BIT 1
+#define WHITE0BIT 0 // 01
+#define WHITE1BIT 1 // 10
#define BLACKBIT 2
-#define FINALIZEDBIT 3
-#define KEYWEAKBIT 3
-#define VALUEWEAKBIT 4
-#define FIXEDBIT 5
-#define SFIXEDBIT 6
-#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
+#define FINALIZEDBIT 3 //标记没有被引用的udata
+#define KEYWEAKBIT 3 //标记弱表的key
+#define VALUEWEAKBIT 4 // 标记弱表的value
+#define FIXEDBIT 5 // 标记lua_state主线程对象不可回收
+#define SFIXEDBIT 6 // 标记lua关键字不要回收
+#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) // 结果是11
#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
@@ -74,6 +74,8 @@
#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
+// g->currentwhite & WHITEBITS是 current white
+// g->currentwhite ^ WHITEBITS是 otherwhite
#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)