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 Oct 2, 2024
1 parent 7582efb commit d6bff11
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 @@ -1492,6 +1492,13 @@ GC_API int GC_CALL GC_invoke_finalizers(void);
/* analysis. */
GC_API void GC_CALL GC_noop1(GC_word);

/* 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);

/* Same as GC_noop1() but for a pointer. */
GC_API void GC_CALL GC_noop1_ptr(volatile void *);

Expand Down
5 changes: 5 additions & 0 deletions mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ GC_API void GC_CALL GC_noop1_ptr(volatile void *p)
# 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. It is done here, since we need to deal with mark */
Expand Down

0 comments on commit d6bff11

Please sign in to comment.