summaryrefslogtreecommitdiffstats
path: root/third_party/harfbuzz-ng/src/hb-object-private.hh
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/harfbuzz-ng/src/hb-object-private.hh')
-rw-r--r--third_party/harfbuzz-ng/src/hb-object-private.hh45
1 files changed, 30 insertions, 15 deletions
diff --git a/third_party/harfbuzz-ng/src/hb-object-private.hh b/third_party/harfbuzz-ng/src/hb-object-private.hh
index e3c9d21..96d1bd3 100644
--- a/third_party/harfbuzz-ng/src/hb-object-private.hh
+++ b/third_party/harfbuzz-ng/src/hb-object-private.hh
@@ -1,7 +1,7 @@
/*
* Copyright © 2007 Chris Wilson
* Copyright © 2009,2010 Red Hat, Inc.
- * Copyright © 2011 Google, Inc.
+ * Copyright © 2011,2012 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
@@ -47,16 +47,16 @@
/* reference_count */
+#define HB_REFERENCE_COUNT_INVALID_VALUE ((hb_atomic_int_t) -1)
+#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE}
struct hb_reference_count_t
{
hb_atomic_int_t ref_count;
-#define HB_REFERENCE_COUNT_INVALID_VALUE ((hb_atomic_int_t) -1)
-#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE}
-
- inline void init (int v) { const_cast<hb_atomic_int_t &> (ref_count) = v; }
+ inline void init (int v) { ref_count = v; }
inline int inc (void) { return hb_atomic_int_add (const_cast<hb_atomic_int_t &> (ref_count), 1); }
inline int dec (void) { return hb_atomic_int_add (const_cast<hb_atomic_int_t &> (ref_count), -1); }
+ inline void finish (void) { ref_count = HB_REFERENCE_COUNT_INVALID_VALUE; }
inline bool is_invalid (void) const { return ref_count == HB_REFERENCE_COUNT_INVALID_VALUE; }
@@ -65,8 +65,11 @@ struct hb_reference_count_t
/* user_data */
+#define HB_USER_DATA_ARRAY_INIT {HB_LOCKABLE_SET_INIT}
struct hb_user_data_array_t
{
+ /* TODO Add tracing. */
+
struct hb_user_data_item_t {
hb_user_data_key_t *key;
void *data;
@@ -78,16 +81,20 @@ struct hb_user_data_array_t
void finish (void) { if (destroy) destroy (data); }
};
- hb_lockable_set_t<hb_user_data_item_t, hb_static_mutex_t> items;
+ hb_lockable_set_t<hb_user_data_item_t, hb_mutex_t> items;
+
+ inline void init (void) { items.init (); }
HB_INTERNAL bool set (hb_user_data_key_t *key,
void * data,
hb_destroy_func_t destroy,
- hb_bool_t replace);
+ hb_bool_t replace,
+ hb_mutex_t &lock);
- HB_INTERNAL void *get (hb_user_data_key_t *key);
+ HB_INTERNAL void *get (hb_user_data_key_t *key,
+ hb_mutex_t &lock);
- HB_INTERNAL void finish (void);
+ HB_INTERNAL void finish (hb_mutex_t &lock);
};
@@ -96,9 +103,10 @@ struct hb_user_data_array_t
struct hb_object_header_t
{
hb_reference_count_t ref_count;
+ hb_mutex_t lock;
hb_user_data_array_t user_data;
-#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID}
+#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID, HB_MUTEX_INIT, HB_USER_DATA_ARRAY_INIT}
static inline void *create (unsigned int size) {
hb_object_header_t *obj = (hb_object_header_t *) calloc (1, size);
@@ -111,6 +119,8 @@ struct hb_object_header_t
inline void init (void) {
ref_count.init (1);
+ lock.init ();
+ user_data.init ();
}
inline bool is_inert (void) const {
@@ -129,9 +139,9 @@ struct hb_object_header_t
if (ref_count.dec () != 1)
return false;
- ref_count.init (HB_REFERENCE_COUNT_INVALID_VALUE);
-
- user_data.finish ();
+ ref_count.finish (); /* Do this before user_data */
+ user_data.finish (lock);
+ lock.finish ();
return true;
}
@@ -143,11 +153,14 @@ struct hb_object_header_t
if (unlikely (!this || this->is_inert ()))
return false;
- return user_data.set (key, data, destroy_func, replace);
+ return user_data.set (key, data, destroy_func, replace, lock);
}
inline void *get_user_data (hb_user_data_key_t *key) {
- return user_data.get (key);
+ if (unlikely (!this || this->is_inert ()))
+ return NULL;
+
+ return user_data.get (key, lock);
}
inline void trace (const char *function) const {
@@ -160,6 +173,8 @@ struct hb_object_header_t
this ? ref_count.ref_count : 0);
}
+ private:
+ ASSERT_POD ();
};