[babl] Made babl_hash_table_find thread safe by making find_func an argument.



commit 3021d2da521884e9753a8e84d31ed61d994a8ea6
Author: �yvind Kolås <pippin gimp org>
Date:   Sat Nov 21 16:05:00 2009 +0000

    Made babl_hash_table_find thread safe by making find_func an argument.

 babl/babl-db.c         |   27 +++++++++++++++++++--------
 babl/babl-fish.c       |    6 ++----
 babl/babl-hash-table.c |   14 ++++++++++----
 babl/babl-hash-table.h |    7 ++++---
 4 files changed, 35 insertions(+), 19 deletions(-)
---
diff --git a/babl/babl-db.c b/babl/babl-db.c
index 74413d8..db0b45b 100644
--- a/babl/babl-db.c
+++ b/babl/babl-db.c
@@ -82,13 +82,18 @@ Babl *
 babl_db_find (BablDb     *db,
               const char *name)
 {
-  return babl_hash_table_find (db->name_hash, babl_hash_by_str (db->name_hash, name), (void *) name);
+  Babl *ret;
+  ret = babl_hash_table_find (db->name_hash, babl_hash_by_str (db->name_hash, name),
+                              NULL, (void *) name);
+  return ret;
 }
 
 int
 babl_db_count (BablDb *db)
 {
-  return db->babl_list->count;
+  int ret;
+  ret = db->babl_list->count;
+  return ret;
 }
 
 Babl *
@@ -104,7 +109,6 @@ babl_db_insert (BablDb *db,
   * place to brand them with where the item came from. */
   item->instance.creator = babl_extender ();
   return item;
-
 }
 
 void
@@ -121,22 +125,29 @@ babl_db_exist (BablDb     *db,
                int        id,
                const char *name)
 {
+  Babl *ret;
   if (id)
-    return babl_hash_table_find (db->id_hash, babl_hash_by_int (db->id_hash, id), &id);
-  return babl_hash_table_find (db->name_hash, babl_hash_by_str (db->name_hash, name), (void *) name);
+    ret = babl_hash_table_find (db->id_hash, babl_hash_by_int (db->id_hash, id), NULL, &id);
+  else 
+    ret = babl_hash_table_find (db->name_hash, babl_hash_by_str (db->name_hash, name), NULL, (void *) name);
+  return ret;
 }
 
 Babl *
 babl_db_exist_by_id (BablDb *db,
                      int    id)
 {
-  return  babl_hash_table_find (db->id_hash, babl_hash_by_int (db->id_hash, id),  &id);
+  Babl *ret;
+  ret = babl_hash_table_find (db->id_hash, babl_hash_by_int (db->id_hash, id), NULL, &id);
+  return ret;
 }
 
 Babl *
 babl_db_exist_by_name (BablDb     *db,
                        const char *name)
 {
-  return  babl_hash_table_find (db->name_hash, babl_hash_by_str (db->name_hash, name), (void *) name);
+  Babl *ret;
+  ret = babl_hash_table_find (db->name_hash, babl_hash_by_str (db->name_hash, name),
+                              NULL, (void *) name);
+  return ret;
 }
-
diff --git a/babl/babl-fish.c b/babl/babl-fish.c
index ae25bcb..d2cda12 100644
--- a/babl/babl-fish.c
+++ b/babl/babl-fish.c
@@ -211,8 +211,7 @@ babl_fish (const void *source,
         /* In the case of equal source and destination formats
          * we will search through the fish database for reference fish
          * to handle the memcpy */
-        id_htable->find_func = find_memcpy_fish;
-        babl_hash_table_find (id_htable, hashval, (void *) &ffish);
+        babl_hash_table_find (id_htable, hashval, find_memcpy_fish, (void *) &ffish);
       }
     else
       {
@@ -229,8 +228,7 @@ babl_fish (const void *source,
          * insert it into the fish database to indicate non-existent fish
          * path.
          */
-        id_htable->find_func = find_fish_path;
-        babl_hash_table_find (id_htable, hashval, (void *) &ffish);
+        babl_hash_table_find (id_htable, hashval, find_fish_path, (void *) &ffish);
 
         if (ffish.fish_path)
           {
diff --git a/babl/babl-hash-table.c b/babl/babl-hash-table.c
index a9c5deb..a3f8364 100644
--- a/babl/babl-hash-table.c
+++ b/babl/babl-hash-table.c
@@ -194,9 +194,10 @@ babl_hash_table_insert (BablHashTable *htab,
 }
 
 Babl *
-babl_hash_table_find (BablHashTable *htab,
-                      int           hash,
-                      void          *data)
+babl_hash_table_find (BablHashTable       *htab,
+                      int                  hash,
+                      BablHashFindFunction find_func,
+                      void                *data)
 {
   int  it;
   Babl *item;
@@ -211,7 +212,12 @@ babl_hash_table_find (BablHashTable *htab,
 
   for (;;)
     {
-      if (htab->find_func (item, data))
+      if (find_func)
+        {
+          if (find_func (item, data))
+            return item;
+        }
+      else if (htab->find_func (item, data))
         return item;
       it = htab->chain_table[it];
       if (it == -1)
diff --git a/babl/babl-hash-table.h b/babl/babl-hash-table.h
index 881d1d6..ec546f3 100644
--- a/babl/babl-hash-table.h
+++ b/babl/babl-hash-table.h
@@ -60,9 +60,10 @@ babl_hash_table_insert (BablHashTable *htab,
                         Babl          *item);
 
 Babl *
-babl_hash_table_find (BablHashTable *htab,
-                      int           hash,
-                      void          *data);
+babl_hash_table_find (BablHashTable       *htab,
+                      int                  hash,
+                      BablHashFindFunction find_func,
+                      void                *data);
 
 void
 babl_hash_table_destroy (BablHashTable *htab);



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