[babl] Made the each babl type db in babl have a mutex.



commit 2405f947c0b4ebfa7c1474113fb8e2cae25c4b4c
Author: �yvind Kolås <pippin gimp org>
Date:   Sat Nov 21 16:15:04 2009 +0000

    Made the each babl type db in babl have a mutex.
    
    We lock only on mutations of the databases, when reading from them no
    locks are needed.

 babl/babl-db.c |   12 ++++++------
 babl/babl-db.h |    3 +++
 2 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/babl/babl-db.c b/babl/babl-db.c
index db0b45b..38b0596 100644
--- a/babl/babl-db.c
+++ b/babl/babl-db.c
@@ -63,6 +63,7 @@ babl_db_init (void)
   db->name_hash = babl_hash_table_init (db_hash_by_name, db_find_by_name);
   db->id_hash = babl_hash_table_init (db_hash_by_id, db_find_by_id);
   db->babl_list = babl_list_init ();
+  db->mutex = babl_mutex_new ();
 
   return db;
 }
@@ -72,6 +73,7 @@ babl_db_destroy (BablDb *db)
 {
   babl_assert (db);
 
+  babl_mutex_destroy (db->mutex);
   babl_hash_table_destroy (db->name_hash);
   babl_hash_table_destroy (db->id_hash);
   babl_list_destroy (db->babl_list);
@@ -82,24 +84,21 @@ Babl *
 babl_db_find (BablDb     *db,
               const char *name)
 {
-  Babl *ret;
-  ret = babl_hash_table_find (db->name_hash, babl_hash_by_str (db->name_hash, name),
+  return 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)
 {
-  int ret;
-  ret = db->babl_list->count;
-  return ret;
+  return db->babl_list->count;
 }
 
 Babl *
 babl_db_insert (BablDb *db,
                 Babl   *item)
 {
+  babl_mutex_lock (db->mutex);
   if (item->instance.id)
     babl_hash_table_insert (db->id_hash, item);
   babl_hash_table_insert (db->name_hash, item);
@@ -108,6 +107,7 @@ babl_db_insert (BablDb *db,
   /* this point all registered items pass through, a nice
   * place to brand them with where the item came from. */
   item->instance.creator = babl_extender ();
+  babl_mutex_unlock (db->mutex);
   return item;
 }
 
diff --git a/babl/babl-db.h b/babl/babl-db.h
index 3d76ca2..6b4e6ff 100644
--- a/babl/babl-db.h
+++ b/babl/babl-db.h
@@ -25,6 +25,8 @@
 
 #include "babl-list.h"
 #include "babl-hash-table.h"
+#include "babl-memory.h"
+#include "babl-mutex.h"
 
 typedef struct _BablDb BablDb;
 
@@ -33,6 +35,7 @@ typedef struct _BablDb
   BablHashTable *name_hash;
   BablHashTable *id_hash;
   BablList      *babl_list;
+  BablMutex     *mutex;
 } _BablDb;
 
 



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