Skip to content

Commit

Permalink
Merge pull request #24 from jacob-hughes/keep_alive_api
Browse files Browse the repository at this point in the history
Allow external use of keep-alive API
  • Loading branch information
ltratt committed Sep 9, 2024
2 parents 0da451d + 5fe2387 commit a69f8b7
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 a69f8b7

Please sign in to comment.