mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* gc.c (slot_sweep, rb_gc_finalize_deferred)
(rb_objspace_call_finalizer, rb_gc): run finalizers sequencially. [ruby-dev:44562] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ce515f5c8f
commit
a73b88ae43
2 changed files with 17 additions and 3 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Thu Sep 29 11:53:56 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* gc.c (slot_sweep, rb_gc_finalize_deferred)
|
||||||
|
(rb_objspace_call_finalizer, rb_gc): run finalizers
|
||||||
|
sequencially. [ruby-dev:44562]
|
||||||
|
|
||||||
Thu Sep 29 20:37:38 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Sep 29 20:37:38 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ext/gdbm/gdbm.c (rb_gdbm_fatal): adjust argument type.
|
* ext/gdbm/gdbm.c (rb_gdbm_fatal): adjust argument type.
|
||||||
|
|
14
gc.c
14
gc.c
|
@ -345,6 +345,7 @@ typedef struct rb_objspace {
|
||||||
int dont_gc;
|
int dont_gc;
|
||||||
int dont_lazy_sweep;
|
int dont_lazy_sweep;
|
||||||
int during_gc;
|
int during_gc;
|
||||||
|
rb_atomic_t finalizing;
|
||||||
} flags;
|
} flags;
|
||||||
struct {
|
struct {
|
||||||
st_table *table;
|
st_table *table;
|
||||||
|
@ -387,6 +388,7 @@ int *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress;
|
||||||
#define heaps_freed objspace->heap.freed
|
#define heaps_freed objspace->heap.freed
|
||||||
#define dont_gc objspace->flags.dont_gc
|
#define dont_gc objspace->flags.dont_gc
|
||||||
#define during_gc objspace->flags.during_gc
|
#define during_gc objspace->flags.during_gc
|
||||||
|
#define finalizing objspace->flags.finalizing
|
||||||
#define finalizer_table objspace->final.table
|
#define finalizer_table objspace->final.table
|
||||||
#define deferred_final_list objspace->final.deferred
|
#define deferred_final_list objspace->final.deferred
|
||||||
#define mark_stack objspace->markstack.buffer
|
#define mark_stack objspace->markstack.buffer
|
||||||
|
@ -2064,7 +2066,7 @@ slot_sweep(rb_objspace_t *objspace, struct heaps_slot *sweep_slot)
|
||||||
}
|
}
|
||||||
objspace->heap.final_num += final_num;
|
objspace->heap.final_num += final_num;
|
||||||
|
|
||||||
if (deferred_final_list) {
|
if (deferred_final_list && !finalizing) {
|
||||||
rb_thread_t *th = GET_THREAD();
|
rb_thread_t *th = GET_THREAD();
|
||||||
if (th) {
|
if (th) {
|
||||||
RUBY_VM_SET_FINALIZER_INTERRUPT(th);
|
RUBY_VM_SET_FINALIZER_INTERRUPT(th);
|
||||||
|
@ -2968,7 +2970,10 @@ finalize_deferred(rb_objspace_t *objspace)
|
||||||
void
|
void
|
||||||
rb_gc_finalize_deferred(void)
|
rb_gc_finalize_deferred(void)
|
||||||
{
|
{
|
||||||
finalize_deferred(&rb_objspace);
|
rb_objspace_t *objspace = &rb_objspace;
|
||||||
|
if (ATOMIC_SET(finalizing, 1)) return;
|
||||||
|
finalize_deferred(objspace);
|
||||||
|
ATOMIC_SET(finalizing, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -3020,6 +3025,8 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
||||||
/* run finalizers */
|
/* run finalizers */
|
||||||
gc_clear_mark_on_sweep_slots(objspace);
|
gc_clear_mark_on_sweep_slots(objspace);
|
||||||
|
|
||||||
|
if (ATOMIC_SET(finalizing, 1)) return;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* XXX: this loop will make no sense */
|
/* XXX: this loop will make no sense */
|
||||||
/* because mark will not be removed */
|
/* because mark will not be removed */
|
||||||
|
@ -3082,6 +3089,7 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
||||||
|
|
||||||
st_free_table(finalizer_table);
|
st_free_table(finalizer_table);
|
||||||
finalizer_table = 0;
|
finalizer_table = 0;
|
||||||
|
ATOMIC_SET(finalizing, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -3089,7 +3097,7 @@ rb_gc(void)
|
||||||
{
|
{
|
||||||
rb_objspace_t *objspace = &rb_objspace;
|
rb_objspace_t *objspace = &rb_objspace;
|
||||||
garbage_collect(objspace);
|
garbage_collect(objspace);
|
||||||
finalize_deferred(objspace);
|
if (!finalizing) finalize_deferred(objspace);
|
||||||
free_unused_heaps(objspace);
|
free_unused_heaps(objspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue