[Pixman] Making ref counting thread safe

Soeren Sandmann sandmann at daimi.au.dk
Thu Dec 23 19:05:07 PST 2010


Christian Hergert <christian.hergert at gmail.com> writes:

> If I where to go through and work on making the reference counting
> thread safe, what things would I need to make sure I take into
> account for the patch to be accepted? For example:

I put up some notes on the subject here:

    http://cgit.freedesktop.org/~sandmann/pixman/commit/?h=docs&id=773a9833cb4bb887239dd358cf584e1499276f4a

Basically, the only two types of systems that really matter is Windows
and pthreads.

On Windows we always have atomic primitives available through the
Interlocked* functions. On pthreads, we can statically initialize
mutexes, so if worst comes to worst, we can fake the atomics with
mutexes.

>   * Do we just need to use __sync_fetch_and_add()/__sync_sub_and_fetch()
>     within the functions?

I think they should be hidden behind PIXMAN_ATOMIC_* macros.

>   * Should we abstract the atomic operations to support compilers other
>     than GCC? If so, what compilers do we need to support?

With the approach described in the link above, I think it should be
possible to support most compilers without too much trouble.

>   * Do we wan't to fallback to ++/-- when used under X since threading
>     isn't needed? (Add something like pixman_thread_init()).

Wouldn't any such mechanism have overhead in itself? In any case, I
don't think this would be necessary until benchmarks say otherwise.

>   * Is it okay to start with just pixman_image_t and support others
>     in future patches?

I think that's fine.


Thanks,
Soren


More information about the Pixman mailing list