• Emmanuele Bassi's avatar
    Add reference counting types · 9e5a53d5
    Emmanuele Bassi authored
    We have a common pattern for reference counting in GLib, but we always
    implement it with ad hoc code. This is a good chance at trying to
    standardise the implementation and make it public, so that other code
    using GLib can take advantage of shared behaviour and semantics.
    Instead of simply taking an integer variable, we should create type
    aliases, to immediately distinguish the reference counting semantics of
    the code; we can handle mixing atomic reference counting with a
    non-atomic type (and vice versa) by using differently signed values for
    the atomic and non-atomic cases.
    The gatomicrefcount type is modelled on the Linux kernel refcount_t
    type; the grefcount type is added to let single-threaded code bases to
    avoid paying the price of atomic memory barriers on reference counting
gtypes.h 19.1 KB