wingo pushed a commit to branch wip-whippet
in repository guile.

commit 283721b39a8b8aeb9ffaaaddf0ad5750a2712c43
Author: Andy Wingo <wi...@igalia.com>
AuthorDate: Fri Mar 4 15:27:22 2022 +0100

    Refactor handling of precise and conservative roots
---
 Makefile             |  4 ++--
 bdw.h                | 18 ++----------------
 conservative-roots.h |  7 +++++++
 precise-roots.h      | 19 +++++++++++++++++++
 semi.h               | 20 +-------------------
 5 files changed, 31 insertions(+), 37 deletions(-)

diff --git a/Makefile b/Makefile
index 3b301d3b7..bd8e4dc8b 100644
--- a/Makefile
+++ b/Makefile
@@ -8,10 +8,10 @@ ALL_TESTS=$(foreach COLLECTOR,$(COLLECTORS),$(addprefix 
$(COLLECTOR)-,$(TESTS)))
 
 all: $(ALL_TESTS)
 
-bdw-%: bdw.h %.c
+bdw-%: bdw.h conservative-roots.h %.c
        $(CC) $(CFLAGS) -lpthread `pkg-config --libs --cflags bdw-gc` -I. 
-DGC_BDW -o $@ $*.c
 
-semi-%: semi.h %.c
+semi-%: semi.h precise-roots.h %.c
        $(CC) $(CFLAGS) -I. -DGC_SEMI -o $@ $*.c
 
 check: $(addprefix test-$(TARGET),$(TARGETS))
diff --git a/bdw.h b/bdw.h
index 571f67639..7a5538d40 100644
--- a/bdw.h
+++ b/bdw.h
@@ -1,3 +1,5 @@
+#include "conservative-roots.h"
+
 // When pthreads are used, let `libgc' know about it and redirect
 // allocation calls such as `GC_MALLOC ()' to (contention-free, faster)
 // thread-local allocation.
@@ -32,22 +34,6 @@ static inline void* allocate(struct context *cx, enum 
alloc_kind kind,
   abort();
 }
 
-struct handle {
-  void *v;
-};
-
-#define HANDLE_TO(T) union { T* v; struct handle handle; }
-#define HANDLE_REF(h) h.v
-#define HANDLE_SET(h,val) do { h.v = val; } while (0)
-#define PUSH_HANDLE(cx, h) push_handle(cx, &h.handle)
-#define POP_HANDLE(cx, h) pop_handle(cx, &h.handle)
-
-static inline void push_handle(struct context *cx, struct handle *handle) {
-}
-
-static inline void pop_handle(struct context *cx, struct handle *handle) {
-}
-
 static inline void init_field(void **addr, void *val) {
   *addr = val;
 }
diff --git a/conservative-roots.h b/conservative-roots.h
new file mode 100644
index 000000000..7f2db0abd
--- /dev/null
+++ b/conservative-roots.h
@@ -0,0 +1,7 @@
+struct handle { void *unused; };
+
+#define HANDLE_TO(T) union { T* v; struct handle handle; }
+#define HANDLE_REF(h) h.v
+#define HANDLE_SET(h,val) do { h.v = val; } while (0)
+#define PUSH_HANDLE(cx, h) do { (void) &h; } while (0)
+#define POP_HANDLE(cx, h) do { (void) &h; } while (0)
diff --git a/precise-roots.h b/precise-roots.h
new file mode 100644
index 000000000..919154b99
--- /dev/null
+++ b/precise-roots.h
@@ -0,0 +1,19 @@
+struct handle {
+  void *v;
+  struct handle *next;
+};
+
+#define HANDLE_TO(T) union { T* v; struct handle handle; }
+#define HANDLE_REF(h) h.v
+#define HANDLE_SET(h,val) do { h.v = val; } while (0)
+#define PUSH_HANDLE(cx, h) push_handle(&cx->roots, &h.handle)
+#define POP_HANDLE(cx, h) pop_handle(&cx->roots, &h.handle)
+
+static inline void push_handle(struct handle **roots, struct handle *handle) {
+  handle->next = *roots;
+  *roots = handle;
+}
+
+static inline void pop_handle(struct handle **roots, struct handle *handle) {
+  *roots = handle->next;
+}
diff --git a/semi.h b/semi.h
index 16bb8566c..37b9f4ef4 100644
--- a/semi.h
+++ b/semi.h
@@ -4,10 +4,7 @@
 #include <sys/mman.h>
 #include <unistd.h>
 
-struct handle {
-  void *v;
-  struct handle *next;
-};
+#include "precise-roots.h"
 
 struct context {
   uintptr_t hp;
@@ -143,21 +140,6 @@ static inline void* allocate(struct context *cx, enum 
alloc_kind kind,
   }
 }
 
-#define HANDLE_TO(T) union { T* v; struct handle handle; }
-#define HANDLE_REF(h) h.v
-#define HANDLE_SET(h,val) do { h.v = val; } while (0)
-#define PUSH_HANDLE(cx, h) push_handle(cx, &h.handle)
-#define POP_HANDLE(cx, h) pop_handle(cx, &h.handle)
-
-static inline void push_handle(struct context *cx, struct handle *handle) {
-  handle->next = cx->roots;
-  cx->roots = handle;
-}
-
-static inline void pop_handle(struct context *cx, struct handle *handle) {
-  cx->roots = handle->next;
-}
-
 static inline void init_field(void **addr, void *val) {
   *addr = val;
 }

Reply via email to