[babl] babl-image: thread-proof single item cache of babl-images



commit 49df3a07697c3ddab067a89c8541930a7218cf40
Author: Øyvind Kolås <pippin gimp org>
Date:   Sat Nov 3 13:44:42 2018 +0100

    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.

 babl/babl-image.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
---
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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]