[HarfBuzz] harfbuzz-ng: Branch 'master' - 2 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Thu May 5 12:34:36 PDT 2011


 src/hb-common.cc         |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/hb-object-private.hh |   23 ++++-------------------
 2 files changed, 51 insertions(+), 19 deletions(-)

New commits:
commit 46df6828513d56cd60467e36cbe45aa06648f488
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 5 15:33:19 2011 -0400

    Make user_data access threadsafe
    
    For now, by taking a global user_data mutex.

diff --git a/src/hb-common.cc b/src/hb-common.cc
index 68c8711..b000340 100644
--- a/src/hb-common.cc
+++ b/src/hb-common.cc
@@ -264,6 +264,14 @@ hb_script_get_horizontal_direction (hb_script_t script)
 
 /* hb_user_data_array_t */
 
+
+/* NOTE: Currently we use a global lock for user_data access
+ * threadsafety.  If one day we add a mutex to any object, we
+ * should switch to using that insted for these too.
+ */
+
+static hb_static_mutex_t user_data_mutex;
+
 bool
 hb_user_data_array_t::set (hb_user_data_key_t *key,
 			   void *              data,
@@ -271,19 +279,32 @@ hb_user_data_array_t::set (hb_user_data_key_t *key,
 {
   if (!key)
     return false;
+
+  hb_mutex_lock (&user_data_mutex);
+
   if (!data && !destroy) {
     items.remove (key);
     return true;
   }
   hb_user_data_item_t item = {key, data, destroy};
-  return !!items.insert (item);
+  bool ret = !!items.insert (item);
+
+  hb_mutex_unlock (&user_data_mutex);
+
+  return ret;
 }
 
 void *
 hb_user_data_array_t::get (hb_user_data_key_t *key)
 {
+  hb_mutex_lock (&user_data_mutex);
+
   hb_user_data_item_t *item = items.find (key);
-  return item ? item->data : NULL;
+  void *ret = item ? item->data : NULL;
+
+  hb_mutex_unlock (&user_data_mutex);
+
+  return ret;
 }
 
 
diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh
index d3207b0..a0d5fe8 100644
--- a/src/hb-object-private.hh
+++ b/src/hb-object-private.hh
@@ -104,8 +104,6 @@ typedef struct {
 
 /* user_data */
 
-/* XXX make this thread-safe, somehow! */
-
 struct hb_user_data_array_t {
 
   struct hb_user_data_item_t {
commit 218e67b9eefa26e2e4fe43f99a84d082b185b1b0
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu May 5 15:28:37 2011 -0400

    Shrink code

diff --git a/src/hb-common.cc b/src/hb-common.cc
index 368789a..68c8711 100644
--- a/src/hb-common.cc
+++ b/src/hb-common.cc
@@ -29,6 +29,7 @@
 #include "hb-private.hh"
 
 #include "hb-mutex-private.hh"
+#include "hb-object-private.hh"
 
 HB_BEGIN_DECLS
 
@@ -261,4 +262,29 @@ hb_script_get_horizontal_direction (hb_script_t script)
 }
 
 
+/* hb_user_data_array_t */
+
+bool
+hb_user_data_array_t::set (hb_user_data_key_t *key,
+			   void *              data,
+			   hb_destroy_func_t   destroy)
+{
+  if (!key)
+    return false;
+  if (!data && !destroy) {
+    items.remove (key);
+    return true;
+  }
+  hb_user_data_item_t item = {key, data, destroy};
+  return !!items.insert (item);
+}
+
+void *
+hb_user_data_array_t::get (hb_user_data_key_t *key)
+{
+  hb_user_data_item_t *item = items.find (key);
+  return item ? item->data : NULL;
+}
+
+
 HB_END_DECLS
diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh
index dc7dba9..d3207b0 100644
--- a/src/hb-object-private.hh
+++ b/src/hb-object-private.hh
@@ -121,24 +121,11 @@ struct hb_user_data_array_t {
 
   hb_set_t<hb_user_data_item_t> items;
 
-  inline bool set (hb_user_data_key_t *key,
-		   void *              data,
-		   hb_destroy_func_t   destroy)
-  {
-    if (!key)
-      return false;
-    if (!data && !destroy) {
-      items.remove (key);
-      return true;
-    }
-    hb_user_data_item_t item = {key, data, destroy};
-    return !!items.insert (item);
-  }
+  HB_INTERNAL bool set (hb_user_data_key_t *key,
+			void *              data,
+			hb_destroy_func_t   destroy);
 
-  inline void *get (hb_user_data_key_t *key) {
-    hb_user_data_item_t *item = items.find (key);
-    return item ? item->data : NULL;
-  }
+  HB_INTERNAL void *get (hb_user_data_key_t *key);
 
   void finish (void) { items.finish (); }
 };



More information about the HarfBuzz mailing list