90 |
|
|
91 |
unsigned int scm_gc_running_p = 0; |
unsigned int scm_gc_running_p = 0; |
92 |
|
|
93 |
|
/* Lock this mutex before doing lazy sweeping. |
94 |
|
*/ |
95 |
|
scm_t_rec_mutex scm_i_sweep_mutex; |
96 |
|
|
97 |
/* Set this to != 0 if every cell that is accessed shall be checked: |
/* Set this to != 0 if every cell that is accessed shall be checked: |
98 |
*/ |
*/ |
99 |
int scm_debug_cell_accesses_p = 0; |
int scm_debug_cell_accesses_p = 0; |
148 |
else |
else |
149 |
{ |
{ |
150 |
counter = scm_debug_cells_gc_interval; |
counter = scm_debug_cells_gc_interval; |
|
scm_i_thread_put_to_sleep (); |
|
151 |
scm_igc ("scm_assert_cell_valid"); |
scm_igc ("scm_assert_cell_valid"); |
|
scm_i_thread_wake_up (); |
|
152 |
} |
} |
153 |
} |
} |
154 |
} |
} |
460 |
"no longer accessible.") |
"no longer accessible.") |
461 |
#define FUNC_NAME s_scm_gc |
#define FUNC_NAME s_scm_gc |
462 |
{ |
{ |
|
SCM_DEFER_INTS; |
|
|
scm_i_thread_put_to_sleep (); |
|
463 |
scm_igc ("call"); |
scm_igc ("call"); |
|
scm_i_thread_wake_up (); |
|
|
SCM_ALLOW_INTS; |
|
464 |
return SCM_UNSPECIFIED; |
return SCM_UNSPECIFIED; |
465 |
} |
} |
466 |
#undef FUNC_NAME |
#undef FUNC_NAME |
477 |
{ |
{ |
478 |
SCM cell; |
SCM cell; |
479 |
|
|
480 |
scm_i_thread_put_to_sleep (); |
scm_rec_mutex_lock (&scm_i_sweep_mutex); |
481 |
|
|
482 |
*free_cells = scm_i_sweep_some_segments (freelist); |
*free_cells = scm_i_sweep_some_segments (freelist); |
483 |
if (*free_cells == SCM_EOL && scm_i_gc_grow_heap_p (freelist)) |
if (*free_cells == SCM_EOL && scm_i_gc_grow_heap_p (freelist)) |
519 |
|
|
520 |
*free_cells = SCM_FREE_CELL_CDR (cell); |
*free_cells = SCM_FREE_CELL_CDR (cell); |
521 |
|
|
522 |
scm_i_thread_wake_up (); |
scm_rec_mutex_unlock (&scm_i_sweep_mutex); |
523 |
|
|
524 |
return cell; |
return cell; |
525 |
} |
} |
534 |
void |
void |
535 |
scm_igc (const char *what) |
scm_igc (const char *what) |
536 |
{ |
{ |
537 |
|
scm_rec_mutex_lock (&scm_i_sweep_mutex); |
538 |
++scm_gc_running_p; |
++scm_gc_running_p; |
539 |
scm_c_hook_run (&scm_before_gc_c_hook, 0); |
scm_c_hook_run (&scm_before_gc_c_hook, 0); |
540 |
|
|
548 |
#endif |
#endif |
549 |
|
|
550 |
/* During the critical section, only the current thread may run. */ |
/* During the critical section, only the current thread may run. */ |
551 |
#if 0 /* MDJ 021207 <djurfeldt@nada.kth.se> |
scm_i_thread_put_to_sleep (); |
|
Currently, a much larger piece of the GC is single threaded. |
|
|
Can we shrink it again? */ |
|
|
SCM_CRITICAL_SECTION_START; |
|
|
#endif |
|
552 |
|
|
553 |
if (!scm_root || !scm_stack_base || scm_block_gc) |
if (!scm_root || !scm_stack_base || scm_block_gc) |
554 |
{ |
{ |
612 |
scm_c_hook_run (&scm_after_sweep_c_hook, 0); |
scm_c_hook_run (&scm_after_sweep_c_hook, 0); |
613 |
gc_end_stats (); |
gc_end_stats (); |
614 |
|
|
615 |
#if 0 /* MDJ 021207 <djurfeldt@nada.kth.se> */ |
scm_i_thread_wake_up (); |
|
SCM_CRITICAL_SECTION_END; |
|
|
#endif |
|
616 |
|
|
617 |
/* |
/* |
618 |
See above. |
See above. |
619 |
*/ |
*/ |
620 |
scm_c_hook_run (&scm_after_gc_c_hook, 0); |
scm_c_hook_run (&scm_after_gc_c_hook, 0); |
621 |
--scm_gc_running_p; |
--scm_gc_running_p; |
622 |
|
scm_rec_mutex_unlock (&scm_i_sweep_mutex); |
623 |
|
|
624 |
/* |
/* |
625 |
For debugging purposes, you could do |
For debugging purposes, you could do |
879 |
{ |
{ |
880 |
size_t j; |
size_t j; |
881 |
|
|
882 |
|
/* Fixme: Should use mutexattr from the low-level API. */ |
883 |
|
scm_rec_mutex_init (&scm_i_sweep_mutex, &scm_i_plugin_rec_mutex); |
884 |
|
|
885 |
j = SCM_NUM_PROTECTS; |
j = SCM_NUM_PROTECTS; |
886 |
while (j) |
while (j) |
887 |
scm_sys_protects[--j] = SCM_BOOL_F; |
scm_sys_protects[--j] = SCM_BOOL_F; |