Skip to content

Commit

Permalink
gc: add a function to force the collector to run
Browse files Browse the repository at this point in the history
This requires adding a "forced" stage for the collector,
which is the initial stage for a forced collection.
Thereafter, the collector continues to the usual stages
of collection.
  • Loading branch information
yorickhardy committed Nov 15, 2024
1 parent 86cfbeb commit d8aa289
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,14 @@ void gc_collector()
ck_pr_cas_int(&gc_stage, STAGE_SWEEPING, STAGE_RESTING);
}

void gc_force(void)
{
/* try to force the collector to run */
ck_pr_cas_int(&gc_stage, STAGE_RESTING, STAGE_FORCING);
/* if the collector thread was idle, then begin collecting */
ck_pr_cas_int(&gc_stage, STAGE_FORCING, STAGE_CLEAR_OR_MARKING);
}

void *collector_main(void *arg)
{
int stage;
Expand Down
5 changes: 5 additions & 0 deletions include/cyclone/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ void GC(void *, closure, object *, int);
*/
void gc_init_heap(long heap_size);

/**
* \ingroup gc_force
*/
void gc_force(void);

/**
* \defgroup prim Primitives
* @brief Built-in Scheme functions provided by the runtime library
Expand Down
3 changes: 2 additions & 1 deletion include/cyclone/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ typedef enum { STATUS_ASYNC, STATUS_SYNC1, STATUS_SYNC2
/** Stages of the Major GC's collector thread */
typedef enum { STAGE_CLEAR_OR_MARKING, STAGE_TRACING
//, STAGE_REF_PROCESSING
, STAGE_SWEEPING, STAGE_RESTING
, STAGE_SWEEPING, STAGE_RESTING, STAGE_FORCING
} gc_stage_type;

// Constant colors are defined here.
Expand Down Expand Up @@ -377,6 +377,7 @@ struct gc_thread_data_t {

/* GC prototypes */
void gc_initialize(void);
void gc_force(void);
void gc_add_new_unrunning_mutator(gc_thread_data * thd);
void gc_add_mutator(gc_thread_data * thd);
void gc_remove_mutator(gc_thread_data * thd);
Expand Down

0 comments on commit d8aa289

Please sign in to comment.