From: Øyvind Kolås Date: Sat, 3 Nov 2018 12:44:42 +0000 (+0100) Subject: babl-image: thread-proof single item cache of babl-images X-Git-Tag: archive/raspbian/1%0.1.106-3+rpi1^2~15^2~13^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=49df3a07697c3ddab067a89c8541930a7218cf40;p=babl.git babl-image: thread-proof single item cache of babl-images Fixes issue #26, in the end spotted by massimo - for now fixed using gcc extensions rather than also generically with a mutex. --- diff --git a/babl/babl-image.c b/babl/babl-image.c index 04535a4..5ab9765 100644 --- a/babl/babl-image.c +++ b/babl/babl-image.c @@ -105,6 +105,15 @@ babl_image_from_linear (char *buffer, { case BABL_FORMAT: components = format->format.components; + +#if 1 + babl = __atomic_exchange_n (&format->format.image_template, NULL, + __ATOMIC_ACQ_REL); +#else + /* todo: add a configure check for the above gcc extension and use + a mutex if we do not have it? + */ + babl = NULL; if (format->format.image_template != NULL) /* single item cache for speeding up subsequent use of linear buffers for subsequent accesses @@ -112,6 +121,10 @@ babl_image_from_linear (char *buffer, { babl = format->format.image_template; format->format.image_template = NULL; + } +#endif + if (babl) + { for (i = 0; i < components; i++) { babl->image.data[i] = buffer + offset;