mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-10-03 20:29:21 +02:00
There are two ways of using the structs like GMutex, GCond, etc. The first is to explicitly _init() and _clear() them. This is when you use them as part of another structure. This case is not interesting for gcleanup. The other is to have them in static storage (zero-filled) and just use them for the first time. This is the difficult case, because we don't ever free the impl in that case. In the first case, the impl is created and set in the _init() function. We can therfore tell that we are in the second case if we get to the get_impl() function and the impl is not there yet. In that case, add it to the cleanup list. There are probably people that allocate a GMutex as part of a zero-filled structure and use it, then call g_mutex_clear() on it. This is technically a violation of the API and these users will crash with G_DEBUG=cleanup, but that's a good thing because it will cause them to fix their code. All threading primitives are cleaned up on the graveyard shift, so that they can be used by other cleanup functions is libglib. Because GPrivate has a callback, and we need to run that callback for the main thread, we schedule two cleanups for it. The cleanup needs to run in the cleanup scope where the GPrivate callback is defined, so adapt G_PRIVATE_INIT to do this. Tweaked by: Stef Walter <stefw@redhat.com> https://bugzilla.gnome.org/show_bug.cgi?id=711744