From 7babfe5a7904c26060c5b8441ca1bf23e1444f35 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 4 Dec 2012 00:35:54 +0200 Subject: [PATCH] Move object mutext into the user-data array We are not using it for anything lse it seems. --- src/hb-common.cc | 12 ++---------- src/hb-object-private.hh | 24 ++++++++++-------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/hb-common.cc b/src/hb-common.cc index 33a514dbf..9422555cf 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -363,8 +363,7 @@ bool hb_user_data_array_t::set (hb_user_data_key_t *key, void * data, hb_destroy_func_t destroy, - hb_bool_t replace, - hb_mutex_t &lock) + hb_bool_t replace) { if (!key) return false; @@ -382,20 +381,13 @@ hb_user_data_array_t::set (hb_user_data_key_t *key, } void * -hb_user_data_array_t::get (hb_user_data_key_t *key, - hb_mutex_t &lock) +hb_user_data_array_t::get (hb_user_data_key_t *key) { hb_user_data_item_t item = {NULL }; return items.find (key, &item, lock) ? item.data : NULL; } -void -hb_user_data_array_t::finish (hb_mutex_t &lock) -{ - items.finish (lock); -} - /* hb_version */ diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index 0499226aa..8a9ae34db 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -65,7 +65,7 @@ struct hb_reference_count_t /* user_data */ -#define HB_USER_DATA_ARRAY_INIT {HB_LOCKABLE_SET_INIT} +#define HB_USER_DATA_ARRAY_INIT {HB_MUTEX_INIT, HB_LOCKABLE_SET_INIT} struct hb_user_data_array_t { /* TODO Add tracing. */ @@ -81,20 +81,19 @@ struct hb_user_data_array_t void finish (void) { if (destroy) destroy (data); } }; + hb_mutex_t lock; hb_lockable_set_t items; - inline void init (void) { items.init (); } + inline void init (void) { lock.init (); items.init (); } HB_INTERNAL bool set (hb_user_data_key_t *key, void * data, hb_destroy_func_t destroy, - hb_bool_t replace, - hb_mutex_t &lock); + hb_bool_t replace); - HB_INTERNAL void *get (hb_user_data_key_t *key, - hb_mutex_t &lock); + HB_INTERNAL void *get (hb_user_data_key_t *key); - HB_INTERNAL void finish (hb_mutex_t &lock); + inline void finish (void) { items.finish (lock); lock.finish (); } }; @@ -103,10 +102,9 @@ struct hb_user_data_array_t struct hb_object_header_t { hb_reference_count_t ref_count; - hb_mutex_t mutex; hb_user_data_array_t user_data; -#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID, HB_MUTEX_INIT, HB_USER_DATA_ARRAY_INIT} +#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID, HB_USER_DATA_ARRAY_INIT} static inline void *create (unsigned int size) { hb_object_header_t *obj = (hb_object_header_t *) calloc (1, size); @@ -119,7 +117,6 @@ struct hb_object_header_t inline void init (void) { ref_count.init (1); - mutex.init (); user_data.init (); } @@ -140,8 +137,7 @@ struct hb_object_header_t return false; ref_count.finish (); /* Do this before user_data */ - user_data.finish (mutex); - mutex.finish (); + user_data.finish (); return true; } @@ -153,14 +149,14 @@ struct hb_object_header_t if (unlikely (!this || this->is_inert ())) return false; - return user_data.set (key, data, destroy_func, replace, mutex); + return user_data.set (key, data, destroy_func, replace); } inline void *get_user_data (hb_user_data_key_t *key) { if (unlikely (!this || this->is_inert ())) return NULL; - return user_data.get (key, mutex); + return user_data.get (key); } inline void trace (const char *function) const {