unsigned int scm_gc_running_p = 0;
+/* Lock this mutex before doing lazy sweeping.
+ */
+scm_t_rec_mutex scm_i_sweep_mutex;
+
/* Set this to != 0 if every cell that is accessed shall be checked:
*/
int scm_debug_cell_accesses_p = 0;
else
{
counter = scm_debug_cells_gc_interval;
- scm_i_thread_put_to_sleep ();
scm_igc ("scm_assert_cell_valid");
- scm_i_thread_wake_up ();
}
}
}
"no longer accessible.")
#define FUNC_NAME s_scm_gc
{
- SCM_DEFER_INTS;
- scm_i_thread_put_to_sleep ();
scm_igc ("call");
- scm_i_thread_wake_up ();
- SCM_ALLOW_INTS;
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
{
SCM cell;
- scm_i_thread_put_to_sleep ();
+ scm_rec_mutex_lock (&scm_i_sweep_mutex);
*free_cells = scm_i_sweep_some_segments (freelist);
if (*free_cells == SCM_EOL && scm_i_gc_grow_heap_p (freelist))
*free_cells = SCM_FREE_CELL_CDR (cell);
- scm_i_thread_wake_up ();
+ scm_rec_mutex_unlock (&scm_i_sweep_mutex);
return cell;
}
void
scm_igc (const char *what)
{
+ scm_rec_mutex_lock (&scm_i_sweep_mutex);
++scm_gc_running_p;
scm_c_hook_run (&scm_before_gc_c_hook, 0);
#endif
/* During the critical section, only the current thread may run. */
-#if 0 /* MDJ 021207 <djurfeldt@nada.kth.se>
- Currently, a much larger piece of the GC is single threaded.
- Can we shrink it again? */
- SCM_CRITICAL_SECTION_START;
-#endif
+ scm_i_thread_put_to_sleep ();
if (!scm_root || !scm_stack_base || scm_block_gc)
{
scm_c_hook_run (&scm_after_sweep_c_hook, 0);
gc_end_stats ();
-#if 0 /* MDJ 021207 <djurfeldt@nada.kth.se> */
- SCM_CRITICAL_SECTION_END;
-#endif
+ scm_i_thread_wake_up ();
/*
See above.
*/
scm_c_hook_run (&scm_after_gc_c_hook, 0);
--scm_gc_running_p;
+ scm_rec_mutex_unlock (&scm_i_sweep_mutex);
/*
For debugging purposes, you could do
{
size_t j;
+ /* Fixme: Should use mutexattr from the low-level API. */
+ scm_rec_mutex_init (&scm_i_sweep_mutex, &scm_i_plugin_rec_mutex);
+
j = SCM_NUM_PROTECTS;
while (j)
scm_sys_protects[--j] = SCM_BOOL_F;