qdata for main contexts
Submitted by Allison (desrt)
Link to original bug (#708694)
Description
We have these two commonly used patterns in GIO:
-
creating objects that emit signals to the thread-default main context
-
singleton objects that emit signals
Occasionally we combine these two for a semi-singleton there we have one object per-context that emits signals into that context.
Keeping track of these semi-singletons typically involves some sort of hashtable keyed by main context, protected using locking primatives (due to the somewhat obvious threadsafety requirements implied by your support of multiple main contexts). This is possible using our new weakrefs, but it is not the easiest thing to do.
A nice alternative to having a global hashtable keyed by some object is to have qdata on the object itself. This would substantially simplify the implementation of any of these sorts of semi-singleton objects.