[cairo] Atomic reference counting
behdad at behdad.org
Fri Sep 21 15:28:19 PDT 2007
On Fri, 2007-09-21 at 17:43 -0400, Chris Wilson wrote:
> Long ago I promised to reimplement reference counting on top of the gcc
> built-in atomic ops. This work was then pushed behind the memfault
> series of corrections (WIP), as I intended to do it as part of the
> cairo_object_t cleanup. However my testing now includes multi-threaded
> stress tests and the random deaths associated with non-atomic reference
> counting have reared their ugly heads and so it's time has come once
> The first patch adds the atomic ops (specifically the two required for
> reference counting) with a fallback to a mutex based path if the Intel
> __sync__* primitives are not available. There's plenty of room for
> improvement for different architectures here.
> The second patch converts the reference counting within cairo over to
> the new primitives.
> Please review.
Thanks Chris. Like always, impressive work!
My main comment is that lets put the infrastructure for adding other
implementations in place, so we don't have to go on and clean this up
later on like we had to do for mutex stuff.
For that, I suggest:
- Rename the configure test from CAIRO_HAS_ATOMIC_OPS to
- In cairo-atomic-private.h, define CAIRO_HAS_ATOMIC_OPS iff at least
one implementation is found.
- Define a cairo_reference_count_t type that is a struct containing an
implementation-defined type. The implementation-defined type for intel
is simply an int. The wrapper struct is to make sure that reference
counts are not modified directly.
- Instead of _cairo_atomic_inc() and _cairo_atomic_dec_and_test() have
- At that point there probably need to be an initializer macro too.
If you think we'll be using atomic ints for other things in the future,
may make sense to keep the original _cairo_atomic_* too, otherwise, just
move it to cairo_reference_count_t.
> Chris Wilson
"Those who would give up Essential Liberty to purchase a little
Temporary Safety, deserve neither Liberty nor Safety."
-- Benjamin Franklin, 1759
More information about the cairo