Replace the global RWLock with per-object locking. Note that there are three places where we needed to take the globlal lock. g_weak_ref_get(), g_weak_ref_set() and in _object_unref_clear_weak_locations(), during g_object_unref(). The calls during g_object_unref() seem the most relevant here, where we would want to avoid a global lock. Luckily, that global lock only had to be taken if the object ever had a GWeakRef registered, so most objects wouldn't care. The global lock only affects objects, that are ever set via g_weak_ref_set(). Still, try to avoid that global lock. Related to GWeakRef, there are various moments when we don't hold a strong reference to the object. So the per-object lock cannot be on the object itself, because when we want to unlock we no longer have access to the object. And we cannot take a strong reference on the GObject either, because that triggers toggle notifications. And worse, when one thread holds the last strong reference of an object and decides to destroy it, then a `g_weak_ref_set(weak_ref, NULL)` on another thread could acquire a temporary reference, and steal the destruction of the object from the other thread. Instead, we already had a "quark_weak_locations" GData and an allocated structure for tracking the GSList with GWeakRef. Extend that to be ref-counted and have a separate lifetime from the object. This WeakRefData now contains the per-object mutex for locking. We can request the WeakRefData from an object, take a reference to keep it alive, and use it to hold the lock without having the object alive. We also need a bitlock on GWeakRef itself. So to set or get a GWeakRef we must take the per-object lock on the WeakRefData and the lock on the GWeakRef (in this order). During g_weak_ref_set() there may be of course two objects (and two WeakRefData) involved, the previous and the new object. Note that now once an object gets a WeakRefData allocated, it can no longer be freed. It must stick until the object gets destroyed. This allocation happens, once an object is set via g_weak_ref_set(). In other words, objects involved with GWeakRef will have extra data allocated. It may be possible to also release the WeakRefData once it's no longer needed. However, that would be quite complicated, and require additional atomic operations, so it's not clear to be worth it. So it's not done. Instead, the WeakRefData sticks on the object once it's set.
GLib
GLib is the low-level core library that forms the basis for projects such as GTK and GNOME. It provides data structure handling for C, portability wrappers, and interfaces for such runtime functionality as an event loop, threads, dynamic loading, and an object system.
The official download locations are: https://download.gnome.org/sources/glib
The official web site is: https://www.gtk.org/
Installation
See the file ‘INSTALL.md’. There is separate and more in-depth documentation for building GLib on Windows.
Supported versions
Upstream GLib only supports the most recent stable release series, the previous stable release series, and the current development release series. All older versions are not supported upstream and may contain bugs, some of which may be exploitable security vulnerabilities.
See SECURITY.md for more details.
Documentation
API documentation is available online for GLib for the:
Discussion
If you have a question about how to use GLib, seek help on GNOME’s Discourse
instance. Alternatively, ask a question
on StackOverflow and tag it glib
.
Reporting bugs
Bugs should be reported to the GNOME issue tracking system. You will need to create an account for yourself. You may also submit bugs by e-mail (without an account) by e-mailing incoming+gnome-glib-658-issue-@gitlab.gnome.org, but this will give you a degraded experience.
Bugs are for reporting problems in GLib itself, not for asking questions about how to use it. To ask questions, use one of our discussion forums.
In bug reports please include:
- Information about your system. For instance:
- What operating system and version
- For Linux, what version of the C library
- And anything else you think is relevant.
- How to reproduce the bug.
- If you can reproduce it with one of the test programs that are built
in the
tests/
subdirectory, that will be most convenient. Otherwise, please include a short test program that exhibits the behavior. As a last resort, you can also provide a pointer to a larger piece of software that can be downloaded.
- If you can reproduce it with one of the test programs that are built
in the
- If the bug was a crash, the exact text that was printed out when the crash occurred.
- Further information such as stack traces may be useful, but is not necessary.
Contributing to GLib
Please follow the contribution guide to know how to start contributing to GLib.
Patches should be submitted as merge requests to gitlab.gnome.org. If the patch fixes an existing issue, please refer to the issue in your commit message with the following notation (for issue 123):
Closes: #123
Otherwise, create a new merge request that introduces the change. Filing a separate issue is not required.