Skip to content

Commit

Permalink
Add API for getting number of objects finalised
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-hughes committed May 9, 2024
1 parent 49fdfc2 commit be14dd1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fnlz_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ void GC_finalize_buffer(GC_finalization_buffer_hdr* buffer) {
word finalizer_word = (*(word *)obj) & ~(word)FINALIZER_CLOSURE_FLAG;
GC_disclaim_proc finalizer = (GC_disclaim_proc) finalizer_word;
(finalizer)(obj);
GC_num_finalized++;
/* Prevent the object from being re-added to the finalization queue */
*(word *)obj = finalizer_word | HAS_BEEN_FINALIZED_FLAG;
cursor++;
Expand Down Expand Up @@ -327,6 +328,10 @@ GC_INNER void GC_maybe_spawn_finalize_thread()
GC_finalizer_thread_exists = 1;
}

GC_API size_t GC_finalized_total(void) {
return GC_num_finalized;
}

# endif

#endif /* ENABLE_DISCLAIM */
2 changes: 2 additions & 0 deletions include/gc/gc_disclaim.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ GC_API int GC_CALL GC_buffered_finalize_posix_memalign(void ** /* memptr */, siz

GC_API void GC_CALL GC_finalize_objects(void);

GC_API size_t GC_finalized_total(void);

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,8 @@ struct _GC_arrays {
struct GC_current_buffer _fin_buffer_current;
# define GC_finalizer_thread_exists GC_arrays._fin_thread_exists
int _fin_thread_exists;
# define GC_num_finalized GC_arrays._fin_total
unsigned _fin_total;
# endif
# endif
# define n_root_sets GC_arrays._n_root_sets
Expand Down

0 comments on commit be14dd1

Please sign in to comment.