Add API to enable non-atomic ref counting on GObject instances
Submitted by Allison (desrt)
Link to original bug (#765803)
Description
Let's provide a mechanism for disabling atomic refcounting on some GObject instances.
We may eventually enable this automatically for particular object classes, but doing it per-instance is pretty easy when an _init() function can easily flip the switch (effectively enforcing the change for an entire set of objects).
Pretty straight forward: all ref-counting ops in GLib are currently done by reading the current value non-atomically, deciding what case we're in based on that value (toggle refs, last unref, etc.) and then writing the modified value back using an atomic compare-and-exchange.
So here's a simple solution: we store a negative value in the refcount to mean "don't bother with the atomic op". It may be less complicated and more efficient to implement this as a high bit on an unsigned int.
All we need, then, is g_object_disable_atomic_refcount() or something to invert the current value of the refcount.