diff options
author | ivmai <ivmai> | 2009-09-10 18:24:52 +0000 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2011-07-26 21:06:46 +0400 |
commit | 20031fb436cf204632124aaa66c73f2972d533ab (patch) | |
tree | 41592057ae3a55bdc20cf66cd403a51e58c35a4f /finalize.c | |
parent | eae86e9ece3225f1008453220aa8492858e624ec (diff) | |
download | bdwgc-20031fb436cf204632124aaa66c73f2972d533ab.tar.gz |
2009-09-10 Ivan Maidanski <ivmai@mail.ru>
(diff115)
* finalize.c (GC_general_register_disappearing_link,
GC_register_finalizer_inner): Remove unnecessary "ifdef THREADS"
guard for LOCK/UNLOCK().
* finalize.c (GC_general_register_disappearing_link,
GC_register_finalizer_inner): Get GC_oom_fn value before releasing
the lock (to prevent data races).
* gcj_mlc.c (GC_gcj_malloc, GC_debug_gcj_malloc,
GC_gcj_malloc_ignore_off_page): Ditto.
* mallocx.c (GC_generic_malloc_ignore_off_page): Ditto.
* include/gc_inline.h (GC_FAST_MALLOC_GRANS): Use GC_get_oom_fn()
instead of GC_oom_fn (to prevent data races).
* malloc.c (GC_generic_malloc): Ditto.
* mallocx.c (GC_memalign): Ditto.
* pthread_support.c (pthread_create): Ditto.
* gcj_mlc.c (maybe_finalize): Acquire the lock before setting
last_finalized_no value to prevent data races.
* include/gc.h (GC_gc_no, GC_get_gc_no, GC_oom_fn, GC_set_oom_fn,
GC_set_find_leak, GC_set_finalize_on_demand,
GC_set_java_finalization, GC_set_finalizer_notifier,
GC_set_dont_expand, GC_set_full_freq, GC_set_non_gc_bytes,
GC_set_no_dls, GC_set_free_space_divisor, GC_set_max_retries,
GC_set_dont_precollect, GC_set_time_limit, GC_warn_proc): Refine
the comment.
* misc.c (GC_set_oom_fn): Ditto.
* include/gc.h (GC_general_register_disappearing_link): Refine the
comment (replace "soft" word with "weak").
* misc.c (GC_oom_fn, GC_get_gc_no, GC_get_parallel,
GC_set_finalizer_notifier, GC_set_find_leak): Add the comment.
* misc.c (GC_set_oom_fn, GC_get_oom_fn, GC_set_finalizer_notifier,
GC_get_finalizer_notifier): Use LOCK/UNLOCK to prevent data races.
Diffstat (limited to 'finalize.c')
-rw-r--r-- | finalize.c | 55 |
1 files changed, 17 insertions, 38 deletions
@@ -154,9 +154,7 @@ GC_API int GC_CALL GC_general_register_disappearing_link(void * * link, if (((word)link & (ALIGNMENT-1)) || link == NULL) ABORT("Bad arg to GC_general_register_disappearing_link"); -# ifdef THREADS - LOCK(); -# endif + LOCK(); GC_ASSERT(obj != NULL && GC_base(obj) == obj); if (log_dl_table_size == -1 || GC_dl_entries > ((word)1 << log_dl_table_size)) { @@ -171,36 +169,29 @@ GC_API int GC_CALL GC_general_register_disappearing_link(void * * link, for (curr_dl = dl_head[index]; curr_dl != 0; curr_dl = dl_next(curr_dl)) { if (curr_dl -> dl_hidden_link == HIDE_POINTER(link)) { curr_dl -> dl_hidden_obj = HIDE_POINTER(obj); -# ifdef THREADS - UNLOCK(); -# endif + UNLOCK(); return(1); } } new_dl = (struct disappearing_link *) GC_INTERNAL_MALLOC(sizeof(struct disappearing_link),NORMAL); if (0 == new_dl) { -# ifdef THREADS - UNLOCK(); -# endif + GC_oom_func oom_fn = GC_oom_fn; + UNLOCK(); new_dl = (struct disappearing_link *) - GC_oom_fn(sizeof(struct disappearing_link)); + (*oom_fn)(sizeof(struct disappearing_link)); if (0 == new_dl) { return(2); } /* It's not likely we'll make it here, but ... */ -# ifdef THREADS - LOCK(); -# endif + LOCK(); } new_dl -> dl_hidden_obj = HIDE_POINTER(obj); new_dl -> dl_hidden_link = HIDE_POINTER(link); dl_set_next(new_dl, dl_head[index]); dl_head[index] = new_dl; GC_dl_entries++; -# ifdef THREADS - UNLOCK(); -# endif + UNLOCK(); return(0); } @@ -308,11 +299,10 @@ STATIC void GC_register_finalizer_inner(void * obj, size_t index; struct finalizable_object *new_fo; hdr *hhdr; + GC_oom_func oom_fn; DCL_LOCK_STATE; -# ifdef THREADS - LOCK(); -# endif + LOCK(); if (log_fo_table_size == -1 || GC_fo_entries > ((word)1 << log_fo_table_size)) { GC_grow_table((struct hash_chain_entry ***)(&fo_head), @@ -361,9 +351,7 @@ STATIC void GC_register_finalizer_inner(void * obj, fo_set_next(prev_fo, curr_fo); } } -# ifdef THREADS - UNLOCK(); -# endif + UNLOCK(); return; } prev_fo = curr_fo; @@ -372,34 +360,27 @@ STATIC void GC_register_finalizer_inner(void * obj, if (ofn) *ofn = 0; if (ocd) *ocd = 0; if (fn == 0) { -# ifdef THREADS - UNLOCK(); -# endif + UNLOCK(); return; } GET_HDR(base, hhdr); if (0 == hhdr) { /* We won't collect it, hence finalizer wouldn't be run. */ -# ifdef THREADS - UNLOCK(); -# endif + UNLOCK(); return; } new_fo = (struct finalizable_object *) GC_INTERNAL_MALLOC(sizeof(struct finalizable_object),NORMAL); if (EXPECT(0 == new_fo, FALSE)) { -# ifdef THREADS - UNLOCK(); -# endif + oom_fn = GC_oom_fn; + UNLOCK(); new_fo = (struct finalizable_object *) - GC_oom_fn(sizeof(struct finalizable_object)); + (*oom_fn)(sizeof(struct finalizable_object)); if (0 == new_fo) { return; } /* It's not likely we'll make it here, but ... */ -# ifdef THREADS - LOCK(); -# endif + LOCK(); } GC_ASSERT(GC_size(new_fo) >= sizeof(struct finalizable_object)); new_fo -> fo_hidden_base = (word)HIDE_POINTER(base); @@ -410,9 +391,7 @@ STATIC void GC_register_finalizer_inner(void * obj, fo_set_next(new_fo, fo_head[index]); GC_fo_entries++; fo_head[index] = new_fo; -# ifdef THREADS - UNLOCK(); -# endif + UNLOCK(); } GC_API void GC_CALL GC_register_finalizer(void * obj, |