babl-image: thread-proof single item cache of babl-images
authorØyvind Kolås <pippin@gimp.org>
Sat, 3 Nov 2018 12:44:42 +0000 (13:44 +0100)
committerØyvind Kolås <pippin@gimp.org>
Sat, 3 Nov 2018 12:47:00 +0000 (13:47 +0100)
Fixes issue #26, in the end spotted by massimo - for now fixed using gcc
extensions rather than also generically with a mutex.

babl/babl-image.c

index 04535a441d99bb85bcc06ac1155915fbb269f337..5ab976582968e5ff36247b3ec0ecef614339b093 100644 (file)
@@ -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;