Skip to content

Draft: [th/weak-ref-lock] gobject: use per-object bit-lock instead of global RWLock for GWeakRef

Thomas Haller requested to merge th/weak-ref-lock into main

Replace the global RWLock with a per-object locking.

There are 3 problems with this patch:

  1. it requires to add an optional_flags2 field, which (on 64 archs) grows the size of GObject by adding a GObjectPrivate.

  2. g_weak_ref_set() now must temporarily ref+unref the previously set object. This is a visible change in behavior, because this can emit new toggle notifications and an object might now be destroyed on another thread than before.

  3. two unit tests still fail. I cannot understand why that is (help requested). This could be due to 2), although, if a program is bothered by 2), it seems to do something unsound.

Maybe we could get away without 2), if GObject would hold a ref-counted locker object. That would be a struct (of two gint, one for the ref-count and one for the bitlock). The downside of that is this effectively applies to every object (at latest during dispose) and keeping track of that pointer and the struct consumes even more memory. So I think this patch is better... if the unit tests can be fixed.

Edited by Thomas Haller

Merge request reports