Skip to content

Commit

Permalink
Allow external use of keep-alive API
Browse files Browse the repository at this point in the history
The current implementation is a macro which means it cannot be used
directly in Alloy.
  • Loading branch information
jacob-hughes committed Sep 9, 2024
1 parent 0da451d commit 5fe2387
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,13 @@ GC_API int GC_CALL GC_invoke_finalizers(void);
# define GC_reachable_here(ptr) GC_noop1((GC_word)(ptr))
#endif

/* Explicitly tell the collector that an object is reachable */
/* at a particular program point. This prevents the argument */
/* pointer from being optimized away, even it is otherwise no */
/* longer needed. Used to prevent finalizers from running when */
/* the associated object is still in use. */
GC_API void GC_CALL GC_keep_alive(GC_word);

/* Make the argument appear live to compiler. Should be robust against */
/* the whole program analysis. */
GC_API void GC_CALL GC_noop1(GC_word);
Expand Down
5 changes: 5 additions & 0 deletions mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ GC_API void GC_CALL GC_noop1(GC_word x)
# endif
}

GC_API void GC_keep_alive(GC_word x)
{
GC_reachable_here(x);
}

/* Initialize GC_obj_kinds properly and standard free lists properly. */
/* This must be done statically since they may be accessed before */
/* GC_init is called. */
Expand Down

0 comments on commit 5fe2387

Please sign in to comment.