Re[2]: [Gc] Patch for public R/W vars getters and setters

Ivan Maidanski ivmai at mail.ru
Fri Jun 12 23:33:43 PDT 2009


Hi!

"Boehm, Hans" <hans.boehm at hp.com> wrote:
> Thanks!  That was fast!
> 
> I committed the patch.
> 
> I think that most of the getters, as well as the setters that can be safely called after initialization should probably include a LOCK()/UNLOCK().  Otherwise we need to document them as usually requiring GC_call_with_alloc_lock() to avoid data races.  That assumes that none of them are called internally with the allocator lock already held ...
> 
> Hans

Most of these setters are used during initialization only and noramlly called before GC_INIT() (all except GC_set_warn_proc(), GC_set_finalizer_notifier(), GC_set_oom_fn(), GC_set_dont_expand(), GC_set_non_gc_bytes()).

As for GC_get_gc_no(), I think it's better not to add LOCK/UNLOCK to it
as it could be used in the following construction:

 obj = GC_MALLOC(size);
 if ((new_gc_no = GC_get_gc_no()) != old_gc_no) {
  old_gc_no = new_gc_no;
  collection_recently_trigged();
 }

Similar considerations for GC_set/get_non_gc_bytes():

 GC_call_with_alloc_lock(<fn>() {
    GC_set_non_gc_bytes(GC_get_non_gc_bytes() + inc_value);
 });

I think, the only ones, for which LOCK/UNLOCK should be added, are
setters/getters of finalizer_notifier and oom_fn (to replicate the behavior of warn_proc setter/getter).

And, of course, add the comment for the rest ones (except for all_interior_pointers setter/getter).

Bye.


More information about the Gc mailing list